2012-02-13 12 views
7

मैं ऑनजीटवेल कॉल द्वारा खींचा जा रहा एक टीजीआईडी ​​सेल शैली के लिए अनुशंसित समाधान की तलाश कर रहा हूं (जिसे कोशिकाओं को देखने के लिए कहा जाता है)। पृष्ठभूमि के लिए, माइक द्वारा एक उत्कृष्ट प्रतिक्रिया ने दिखाया कि सेल बनने पर टी -लाइन संपत्ति को कैसे लागू किया जाए; लेकिन मेरी अगली चुनौती सेल सामग्री को रंग दे रही है।फायरमोनकी ग्रिड कंट्रोल - एक मूल्य के आधार पर एक सेल स्टाइल करना (ऑनगेटवेल्यू फ़ंक्शन कॉल के माध्यम से)

Previous posting/answer

उद्देश्य सेल विशेषताएं (फ़ॉन्ट, शैली, रंग आदि ...) मूल्य के बारे में मैं सेल "मान" के रूप में वापस जाने के लिए कर रहा हूँ के बदलने के लिए है। नीचे दिए गए उदाहरण में; यह OnGetValue "मान" के लिए एक शैली लागू करेगा जो वापस किया जा रहा है। यह अच्छी तरह से हो सकता है कि हमें इसे एफएम स्टाइलशीट के माध्यम से करना है; या हम सीधे TText विशेषताओं पर जा सकते हैं? आदर्श रूप में, दोनों परिदृश्यों बहुत अच्छा होगा - लेकिन इस स्तर पर मैं या तो समाधान ले जाएगा ... (; -।। पहले से

unit Unit1; 

interface 

uses 
    System.SysUtils, System.Types, System.UITypes, System.Classes, System.Variants, 
    FMX.Types, FMX.Controls, FMX.Forms, FMX.Dialogs, FMX.Objects, FMX.Grid, 
    FMX.Layouts, FMX.Edit; 

type 
    TForm1 = class(TForm) 
    Grid1: TGrid; 
    Button1: TButton; 
    StyleBook1: TStyleBook; 
    procedure Grid1GetValue(Sender: TObject; const Col, Row: Integer; 
     var Value: Variant); 
    procedure Button1Click(Sender: TObject); 
    private 
    { Private declarations } 
    public 
    { Public declarations } 
    end; 

    TStringColNum = class(TStringColumn) 
    private 
    function CreateCellControl: TStyledControl; override; 
    published 
    end; 

var 
    Form1: TForm1; 

implementation 

{$R *.fmx} 

function TStringColNum.CreateCellControl: TStyledControl; 
begin 
    Result:=TTextCell.Create(Self); 
    TTextCell(Result).TextAlign := TTextAlign.taTrailing; 
end; 

procedure TForm1.Button1Click(Sender: TObject); 
begin 
    Grid1.AddObject(TStringColumn.Create(Self)); 
    Grid1.AddObject(TStringColNum.Create(Self)); // Right Aligned column? 

    Grid1.RowCount:=5000; 
    Grid1.ShowScrollBars:=True; 
end; 

procedure TForm1.Grid1GetValue(Sender: TObject; const Col, Row: Integer; 
    var Value: Variant); 
begin 
    if Col=0 then 
    Value:='Row '+IntToStr(Row); 

    if Col=1 then 
    Value := 'Row '+IntToStr(Row); 

// Apply style based on value ? 

end; 

end. 

बहुत धन्यवाद, इयान>

+0

आप 'एक मूल्य के आधार पर' को परिभाषित कर सकते हैं? क्या आपका मतलब है, कहें, यदि मूल्य नकारात्मक है तो फ़ॉन्ट लाल होगा आदि? –

+0

हाय माइक - हाँ; सटीक। मेरे पास दो परिदृश्य हैं लेकिन दोनों एक ही सिद्धांत हैं। एक परिदृश्य ऋणात्मक मूल्य लाल प्रदर्शित किया जाना है और दूसरा परिदृश्य सूची में किसी आइटम को "बोल्ड" करना है (जो मैं चुनता हूं - ग्रिड आयोजित विवरण के कारण; महत्वपूर्ण ग्राहक इत्यादि ...)। अग्रिम में धन्यवाद। इयान। – Ian

उत्तर

5

सबसे पहले, माफी में मेरी आपके अंतिम प्रश्न का उत्तर, CreateCellControl को सेल बनाने के लिए विरासत में जाना चाहिए था। मैंने अपना जवाब संशोधित किया है।

इस प्रश्न के लिए, मैंने फ़ायरमॉन्की सेल पर अपना ब्लॉग पोस्टिंग अपलोड किया है - http://monkeystyler.com/blog/entry/firemonkey-grid-basics-custom-cells-and-columns - इसमें से सामान शामिल हैं पिछला उत्तर, और कस्टम सेल नियंत्रण बनाने में भी शामिल है। आपको अपनी आय से पहले इसे पढ़ने की आवश्यकता होगी ईडी। मैं इंतजार करूँगा।

...

अभी वापस? अच्छा।

ब्लॉग पोस्ट में उदाहरण के बाद।

इसके अलावा, मैंने TTextancialCell को सीधे TTextCell से प्राप्त करने के लिए अद्यतन किया है (जो निश्चित रूप से एक TEDIT है), जो कि अधिक समझ में आता है और शैली के लिए बहुत आसान है।

type TFinancialCell = class(TTextCell) 
    private 
    FIsNegative: Boolean; 
    FIsImportant: Boolean; 
    protected 
    procedure SetData(const Value: Variant); override; 
    procedure ApplyStyle;override; 
    procedure ApplyStyling; 
    public 
    constructor Create(AOwner: TComponent); override; 
    published 
    property IsNegative: Boolean read FIsNegative; 
    property IsImportant: Boolean read FIsImportant; 
    end; 

कोड ऊपर के लिए:

procedure TFinancialCell.ApplyStyle; 
var T: TFMXObject; 
begin 
    inherited; 
    ApplyStyling; 
end; 

procedure TFinancialCell.ApplyStyling; 
begin 
    if IsNegative then 
    FontFill.Color := claRed 
    else 
    FontFill.Color := claBlack; 
    Font.Style := [TFontStyle.fsItalic]; 
    if IsImportant then 
    Font.Style := [TFontStyle.fsBold] 
    else 
    Font.Style := []; 
    if Assigned(Font.OnChanged) then 
    Font.OnChanged(Font); 
    Repaint; 
end; 

constructor TFinancialCell.Create(AOwner: TComponent); 
begin 
    inherited; 
    TextAlign := TTextAlign.taTrailing; 
end; 

procedure TFinancialCell.SetData(const Value: Variant); 
var F: Single; 
    O: TFMXObject; 
    S: String; 
begin 
    S := Value; 
    FIsImportant := S[1] = '#'; 
    if IsImportant then 
    S := Copy(Value,2,MaxInt) 
    else 
    S := Value; 

    F := StrToFloat(S); 
    inherited SetData(Format('%m', [F])); 
    FIsNegative := F < 0; 
    ApplyStyling; 
end; 

और अंत में getValue ईवेंट हैंडलर, अद्यतन:

तो, TFinancialCell अद्यतन

procedure TForm1.Grid1GetValue(Sender: TObject; const Col, Row: Integer; 
    var Value: Variant); 
var Cell: TStyledControl; 
begin 
    if Col = 0 then 
    Value := Row 
    else if Col = 1 then 
    begin 
    Value := FloatToStr(Data[Row]); 
    if Value > 30 then 
     Value := '#'+Value; 
    end; 
end; 
+0

हाय माइक - उदाहरण के लिए फिर से धन्यवाद; आप वास्तव में "टीजीआरडी गुरु" हैं। ब्लॉग पोस्ट/बोर्ड पोस्ट उत्कृष्ट और बहुत अच्छी तरह से प्रस्तुत किया गया है। मैंने आपके संशोधित/संपादित उदाहरण का पालन करने में कामयाब रहा है और बोल्ड और लाल काम अच्छी तरह से प्राप्त किया है। - बहुत धन्यवाद फिर से; एक सच्चे सज्जन ...! इयान। (पी एस।क्या कॉलम हेडिंग को सही तरीके से संरेखित करने का कोई तरीका है साथ ही साथ TFinancial कॉलम के लिए एक ही पद्धति का उपयोग करना .. ..) – Ian

+0

हाय माइक - उपर्युक्त के संबंध में मैंने एक मामूली समस्या देखी है? जब तक मैं खिड़की को स्क्रॉल नहीं करता तब तक सब ठीक दिखता है। जब यह स्क्रॉल करता है, लाल/बोल्ड लाइन/सिंक से बाहर जाते हैं। मुझे यकीन नहीं है कि यह एफएम या कुछ और के साथ एक पश्चाताप मुद्दा है? यदि आपका ठीक है तो मैं अपना कोड पोस्ट कर सकता हूं? - अग्रिम में Thx, इयान। – Ian

+0

मेरा बुरा। स्टाइल को सेटडाटा विधि से पुनः लागू करने की आवश्यकता है, इसलिए मैंने उपरोक्त कोड को एक लागू स्टाइल विधि निकालने के लिए अद्यतन किया है और इसे ApplyStyle, SetData और SetIs महत्वपूर्ण से कॉल करें। –

1

कोड ऊपर के लिए ठीक है XE4 से पहले संस्करण, लेकिन XE4 और XE5 के लिए काम नहीं करता है। पाठ का रंग और शैली बदल नहीं है।

यह XE4 और XE5 के लिए एक निश्चित कोड है:

procedure TFinancialCell.ApplyStyling; 
begin 
    StyledSettings := [TStyledSetting.ssFamily, TStyledSetting.ssSize]; 
    if IsNegative then 
    FontColor := claRed 
    else 
    FontColor := claBlack; 
    Font.Style := [TFontStyle.fsItalic]; 
    if IsImportant then 
    Font.Style := [TFontStyle.fsBold] 
    else 
    Font.Style := []; 
    if Assigned(Font.OnChanged) then 
    Font.OnChanged(Font); 
    Repaint; 
end;