our callback function prototype}
function EnumWinPropsEx(hWnd: HWND; pString: PChar; Data: THandle;
dwData: DWORD): BOOL; stdcall;
var
Form1: TForm1;
implementation
{these steps will be executed for each property
entry in the window's property list}
function EnumWinPropsEx(hWnd: HWND; pString: PChar; Data: THandle;
dwData: DWORD): BOOL;
begin
{add the string and associated value to the list box}
Form1.ListBox1.Items.Add(Format('%s=%d, User Data: %d',
[pString,Data,dwData]));
{continue enumeration}
Result:=TRUE;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
{add a new property to the window's property list}
SetProp(Form1.Handle,PChar(Edit1.Text),StrToInt(Edit2.Text));
{clear the edit boxes}
Edit1.Text:='';
Edit2.Text:='';
{clear the list box}
Form1.ListBox1.Items.Clear;
{list all of the properties associated with the window}
EnumPropsEx(Form1.Handle, @EnumWinPropsEx, 1);
end;
procedure TForm1.Button2Click(Sender: TObject);
begin
{clear the list box}
Form1.ListBox1.Items.Clear;
{list all of the properties associated with the window}
procedure TForm1.Button3Click(Sender: TObject);
begin
{remove the selected property from the property list}
RemoveProp(Form1.Handle,PChar(Copy(ListBox1.Items[ListBox1.ItemIndex],
0,Pos('=',ListBox1.Items[ListBox1.ItemIndex])-1)));
{clear the list box}
Form1.ListBox1.Items.Clear;
{list all of the properties associated with the window}
procedure TForm1.Button4Click(Sender: TObject);
var
Data: THandle; // this stores the property entry data
begin
{get property entry data associated with the given string}
Data:=GetProp(Form1.Handle,PChar(Edit1.Text));
{if there was a property value returned...}
if (Data<>0) then
{...display it...}
{our callback function prototype}
function EnumWinProps(hWnd: HWND; pString: PChar; Data: THandle): BOOL; stdcall;
var
Form1: TForm1;
implementation
{these steps will be executed for each property
entry in the window's property list}
function EnumWinProps(hWnd: HWND; pString: PChar; Data: THandle): BOOL;
begin
{add the string and associated value to the list box}
Form1.ListBox1.Items.Add(Format('%s=%d',[pString,Data]));
{continue enumeration}
Result:=TRUE;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
{add a new property to the window's property list}
SetProp(Form1.Handle,PChar(Edit1.Text),StrToInt(Edit2.Text));
{clear the edit boxes}
Edit1.Text:='';
Edit2.Text:='';
{clear the list box}
Form1.ListBox1.Items.Clear;
{list all of the properties associated with the window}
EnumProps(Form1.Handle, @EnumWinProps);
end;
procedure TForm1.Button2Click(Sender: TObject);
begin
{clear the list box}
Form1.ListBox1.Items.Clear;
{list all of the properties associated with the window}
EnumProps(Form1.Handle, @EnumWinProps);
end;
procedure TForm1.Button3Click(Sender: TObject);
begin
{remove the selected property from the property list}
{list all of the properties associated with the window}
EnumProps(Form1.Handle, @EnumWinProps);
end;
procedure TForm1.Button4Click(Sender: TObject);
var
Data: THandle; // this stores the property entry data
begin
{get property entry data associated with the given string}
Data:=GetProp(Form1.Handle,PChar(Edit1.Text));
{if there was a property value returned...}
if (Data<>0) then
{...display it...}
Edit2.Text:=IntToStr(Data)
else
{...otherwise display an error message}
Edit2.Text:='No property found.';
end;
The Tomes of Delphi 3: Win32 Core API Help File by Larry Diehl
function GetObjectProperty(
const AObject : TObject;
const APropName : string
):TObject;
var
PropInfo:PPropInfo;
begin
Result := nil;
PropInfo:=GetPropInfo(AObject.ClassInfo,APropName);
if Assigned(PropInfo) and
(PropInfo^.PropType^.Kind = tkClass) then
Result := GetObjectProp(AObject,PropInfo);
end;
function SetIntegerPropertyIfExists(
const AObject : TObject;
const APropName : string;
const AValue : integer
):Boolean;
var
PropInfo:PPropInfo;
begin
PropInfo:=GetPropInfo(AObject.ClassInfo,APropName);
if Assigned(PropInfo) and
(PropInfo^.PropType^.Kind = tkInteger) then
begin
SetOrdProp(AObject,PropInfo,AValue);
Result:=True;
end else
Result:=False;
end;
//调用
procedure TFrmTest.FormCreate(Sender: TObject);
var
objTemp : TObject;
begin
objTemp := GetObjectProperty(Self,'Font');
if Assigned(objTemp) then
SetIntegerPropertyIfExists(objTemp,'Size',9);
end;