2

I am not exactly sure how to put this. I am coloring cxDB grid field based on the value:

procedure TForm1.cxGrid1DBTableView1StylesGetContentStyle(
  Sender: TcxCustomGridTableView; ARecord: TcxCustomGridRecord;
  AItem: TcxCustomGridTableItem; var AStyle: TcxStyle);
  var  AColumn: TcxCustomGridTableItem;
begin
AColumn := (Sender as TcxGridDBTableView).GetColumnByFieldName('SIFRA');
 if VarToStr(ARecord.Values[AColumn.Index]) =  '007 01' then
      AStyle := cxstyle1; 
end;

I would like to change the code so that all the fields that have 007 in the column get coloured.

user763539
  • 3,509
  • 6
  • 44
  • 103
  • 1
    Ok, better yet is to use `if StartsText('007', VarToStr(ARecord.Values[AColumn.Index])) then`. – TLama Nov 25 '13 at 01:32
  • your version colors all of my fields. I want only the selected 'sifra' – user763539 Nov 25 '13 at 01:33
  • also StartsText is unreckognised – user763539 Nov 25 '13 at 01:34
  • Add `System.StrUtils` to your `uses` clause. But your problem is not in that condition. You'll need to understand, how that event works. And that's what I can't help you with. – TLama Nov 25 '13 at 01:36
  • Both work the same way. I want to color the specific field in the grid containing 007. Both of your version color ALL of my fields. I dont need that. – user763539 Nov 25 '13 at 01:39
  • I got your question as you're looking for a way to rewrite that `if` condition to apply for all values starting with `007`. That's all I proposed. I don't know anything about how that event works. You obviously need to get more than what you described as *"using of wildcards"*. – TLama Nov 25 '13 at 01:41
  • I need wildcards for that text after the 7: = '007 01' then – user763539 Nov 25 '13 at 01:44
  • That line `if StartsText('007', SomeText) then` evaluates to `True` if the string in `SomeText` variable starts with `007`. So it could be something you may understand as `007*`. If that's what you've asked and it colors all the fields, then you'll need to do something else in that event method. – TLama Nov 25 '13 at 01:54
  • like i said, i dont want all the fields colored but only ones with 007 in them. – user763539 Nov 25 '13 at 02:13
  • Ok, so then I got your question wrong. Can we delete our comments from here to cleanup the workspace, please ? – TLama Nov 25 '13 at 02:15
  • @TLama - I think these comments would serve as a precaution for anyone who would like to sort this out. – Sertac Akyuz Nov 25 '13 at 02:15
  • @Sertac, hm, that's right, but there's a lot of them. Maybe would be fine to include that `StartsText` line into the question. Or emphasize somehow that the way of using that event is wrong. – TLama Nov 25 '13 at 02:18
  • 2
    @TLama - It's your call, but indeed the first comment already answers the question (wildcards I mean). – Sertac Akyuz Nov 25 '13 at 02:20
  • I guess using Lamas suggestion can be done. Just added another style in style repository and fixed the issue. – user763539 Nov 25 '13 at 02:58
  • -1 The comments address the question, but you complain that they do not. Your question is ill-stated. Fix the question to be clear what you are asking. – David Heffernan Nov 25 '13 at 07:51
  • Lama,please post the answer since the first suggestion could do.Thank you ! – user763539 Nov 26 '13 at 13:54
  • 1
    user - You can address a commentator like @TLama (note the @ and correct usage of the account name), then the commentator will be notified. – Sertac Akyuz Nov 26 '13 at 14:53
  • 1
    @TLama - Please post the answer,,,T – user763539 Nov 29 '13 at 01:37

1 Answers1

3

According to comments, you were looking for a way how to write a statement to determine if a certain text starts with a specified string. For this you can use e.g. the StartsText function (System.StrUtils). The following statement will evaluate to True if the current cell text starts with 007:

if StartsText('007', VarToStr(ARecord.Values[AColumn.Index])) then
TLama
  • 75,147
  • 17
  • 214
  • 392