Articles   Members Online:
-Article/Tip Search
-News Group Search over 21 Million news group articles.
-Delphi/Pascal
-CBuilder/C++
-C#Builder/C#
-JBuilder/Java
-Kylix
Member Area
-Home
-Account Center
-Top 10 NEW!!
-Submit Article/Tip
-Forums Upgraded!!
-My Articles
-Edit Information
-Login/Logout
-Become a Member
-Why sign up!
-Newsletter
-Chat Online!
-Indexes NEW!!
Employment
-Build your resume
-Find a job
-Post a job
-Resume Search
Contacts
-Contacts
-Feedbacks
-Link to us
-Privacy/Disclaimer
Embarcadero
Visit Embarcadero
Embarcadero Community
JEDI
Links
How to determine if an object has a particular property Turn on/off line numbers in source code. Switch to Orginial background IDE or DSP color Comment or reply to this aritlce/tip for discussion. Bookmark this article to my favorite article(s). Print this article
19-Oct-02
Category
Object Pascal
Language
Delphi All Versions
Views
136
User Rating
No Votes
# Votes
0
Replies
0
Publisher:
DSP, Administrator
Reference URL:
DKB
			Author: Jonas Bilinkevicius

How to determine if an object has a particular property

Answer:

The first hasprop will return True if a property of name prop exists, eg. 
hasprop(MyLabel,'Caption') will return true while hasprop(MyEdit,'Caption') will 
return false. The second one will set property prop to string value s if it exists 
and is a string type property.

1   hasprop(comp: TComponent; const prop: string): Boolean;
2   var
3     proplist: PPropList;
4     numprops, i: Integer;
5   begin
6     result := false;
7     getmem(proplist, getTypeData(comp.classinfo)^.propcount * Sizeof(Pointer));
8     try
9       NumProps := getproplist(comp.classInfo, tkProperties, proplist);
10      for i := 0 to pred(NumProps) do
11      begin
12        if comparetext(proplist[i]^.Name, prop) = 0 then
13        begin
14          result := true;
15          break;
16        end;
17      end;
18    finally
19      freemem(proplist, getTypeData(comp.classinfo)^.propcount * Sizeof(Pointer));
20    end;
21  end;
22  
23  procedure setcomppropstring(comp: TComponent; const prop, s: string);
24  var
25    proplist: PPropList;
26    numprops, i: Integer;
27  begin
28    getmem(proplist, getTypeData(comp.classinfo)^.propcount * Sizeof(Pointer));
29    try
30      NumProps := getproplist(comp.classInfo, tkProperties, proplist);
31      for i := 0 to pred(NumProps) do
32      begin
33        if (comparetext(proplist[i]^.Name, prop) = 0) and
34          (comparetext(proplist[i]^.proptype^.name, 'string') = 0 then
35          begin
36            setStrProp(comp, proplist[i], s);
37            break;
38          end;
39      end;
40    finally
41      freemem(proplist, getTypeData(comp.classinfo)^.propcount * Sizeof(Pointer));
42    end;
43  end;


			
Vote: How useful do you find this Article/Tip?
Bad Excellent
1 2 3 4 5 6 7 8 9 10

 

Advertisement
Share this page
Advertisement
Download from Google

Copyright © Mendozi Enterprises LLC