1

I have a procedure attached to TField.OnGetText event of field Score like this:

procedure TMyForm.GetScoreText(Sender: TField; var Text: string; DisplayText: Boolean);
begin
    if StrToInt(Sender.AsString) >= 80 and StrToInt(Sender.AsString) <= 100 then
        Text := 'Great!';
    else if StrToInt(Sender.AsString) >= 60 and StrToInt(Sender.AsString) < 80 then
        Text := 'Good';
end;

From OnGetText documentation, I know that when there is no OnGetText handler defined, the Text property of the field is the name as AsString property. But my question is, what value does the var parameter Text get there is an OnGetText defined but the the Text is defined for the current value of the field. That is in my case, what value does the Text get when value of the field Score is something less than 60? Is it Null, or empty string, or something else? I need to know it explicitly because there is some logic that depends on the value being displayed.

I learned from this SO post that there was nothing being displayed for the field when the OnGetText handler procedure has no code, that is body of the procedure is empty.

Community
  • 1
  • 1
Sнаđошƒаӽ
  • 16,753
  • 12
  • 73
  • 90

1 Answers1

5

When an OnGetText assigned and nothing returns in the Text argument, then the result is an empty string.

Look at the Db source:

function TField.GetDisplayText: string;
begin
  Result := '';
  if Assigned(FOnGetText) then
    FOnGetText(Self, Result, True) else
    GetText(Result, True);
end;

The Result initially is set to an empty string and passes it to the FOnGetText if it was assigned.

kobik
  • 21,001
  • 4
  • 61
  • 121
  • Thanks. BTW, where can I see for myself the code you have shown here? That is, I am talking about the source itself ;-) – Sнаđошƒаӽ May 11 '17 at 11:49
  • Welcome. go to your `uses` section and `CTRL + left-click` on `Db`. – kobik May 11 '17 at 12:17
  • 2
    BTW, *"Is it Null, or empty string, or something else..."* A `string` cannot be `Null`. – kobik May 11 '17 at 12:19
  • *A string cannot be Null* - thanks for that. I am not actually coding in delphi, I am converting delphi into C#. Anyway, which IDE provides that `CTRL + left-click`? And any other way without an IDE, because as I already said, I am not developing in delphi, so I shouldn't have an IDE ;-) – Sнаđошƒаӽ May 11 '17 at 12:28
  • Well, do you have Delphi installed with sources? – kobik May 11 '17 at 12:30
  • I am not sure, but I have CodeGear RAD Studio installed. – Sнаđошƒаӽ May 11 '17 at 12:31
  • Look for DB.pas or Data.DB.pas depending on your version in the CodeGear directory. – kobik May 11 '17 at 12:39
  • The *CodeGear* IDEs predate the introduction of unit scopes in XE2. The last CodeGear IDE was RAD Studio 2009 (after Embarcadero purchased CodeGear), the first Embarcadero-branded IDE was RADStudio 2010. So the source file name would be `DB.pas` prior to XE2, and `Data.DB.pas` in XE2 onwards. – Remy Lebeau May 11 '17 at 17:18