Mega Code Archive
Canlı yayında [runtime] nesne özellikleri - rtti
//RTTI: Runtime Type Information
unit GenricU2;
interface
uses
SysUtils, WinTypes, WinProcs, Messages, Classes, Graphics, Controls,
Forms, Dialogs, StdCtrls, Menus, ExtCtrls;
type
TForm1 = class(TForm)
MainMenu1: TMainMenu;
Help1: TMenuItem;
About1: TMenuItem;
Button1: TButton;
Button2: TButton;
Edit1: TEdit;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure About1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
procedure ChangeControls(const Prop: String;
const SetTo: array of const;
const ControlsToChange: array of TComponent);
implementation
uses TypInfo;
{$R *.DFM}
procedure ChangeControls(const Prop: String;
const SetTo: array of const;
const ControlsToChange: array of TComponent);
var
I: integer;
PropInfo: PPropInfo;
begin
for I := Low(ControlsToChange) to High(ControlsToChange) do
begin
PropInfo := GetPropInfo(ControlsToChange[I].ClassInfo, Prop);
if Assigned(PropInfo) then
with TVarRec(SetTo[Low(SetTo)]) do
case VType of
vtInteger, vtBoolean, vtChar:
SetOrdProp(ControlsToChange[I], PropInfo, VInteger);
vtExtended:
SetFloatProp(ControlsToChange[I], PropInfo, VExtended^);
vtString:
SetStrProp(ControlsToChange[I], PropInfo, VString^);
end;
end;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
ChangeControls('Enabled', [False], [Button1, Edit1, About1]);
end;
procedure TForm1.Button2Click(Sender: TObject);
begin
ChangeControls('Enabled', [True], [Button1, Edit1, About1]);
end;
procedure TForm1.About1Click(Sender: TObject);
begin
MessageDlg('About Box', mtInformation, [mbOk], 0);
end;
end.