admin管理员组文章数量:1122832
I want to implement a function that accepts a general parameter and provides detailed information about the parameter, such as its type, value, and if it's an object, its properties.
For example, I would like to pass a variable like this:
var
s: string;
begin
s := 'Hi';
ShowMessage(GetInfo(s)); // Expected output: s: string = 'Hi'
ShowMessage(GetInfo(Label1.Caption)); // Expected output: (Label1: TLabel).Caption: string = 'First name:'
ShowMessage(GetInfo(pb1.Position)); // Expected output: (pb1: TProgressBar).Position: Integer = 70
ShowMessage(GetInfo(Edit1.Font.Color)); // Expected output: ((Edit1: TEdit).Font: TFont).Color: TColor = 16729702
end;
Is it possible to implement a function like GetInfo that understands the parameter and provides such output?
I attempted to use RTTI (Run-Time Type Information) for this, but I couldn’t achieve the expected result. Specifically, I want to retrieve the type, name, and value of the variable or property passed to the function.
Can anyone suggest how to implement this, or provide an example that would work in Delphi?
本文标签:
版权声明:本文标题:Is it possible in Delphi to pass a general parameter to a function and get detailed information about its type and value? - Stac 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736303867a1932033.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论