开发者

Howto make GetFieldName() function

I have:

TMyForm = class(TForm)
strict private
  FMyColumn: TMyGridColumn;
  ...
end;

...

constructor TMyForm.Create;
begin
  ...
  FMyColumn := TMyGridColumn;
  FMyColumn.Name := 'FMyColumn';

  // I wish to substirtute it with a call like this which will return 'FMyColumn'
  FMyColumn.Name := GetFieldName(FMyColumn);
  ...
end;

I need to initialize the component (TMyGridColumn) name with some meaningful name but prefer to not hard-code its name as a string开发者_如何学Go literal.

A non-RTTI solution will be more welcome.


An object does not have any knowledge, a priori, of which fields or variables refer to it. So without more information you can't write such a function.

If your function knew which object had a reference to the column, then it could use RTTI to find its name. Without RTTI you cannot hope to do this.

I think the fundamental problem you are having is that, although you name the function GetFieldName, you are not passing a field. You are passing an object reference.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜