Watch, Follow, &
Connect with Us

For forums, blogs and more please visit our
Developer Tools Community.


ID: 16188, How to return the name of a unit that a class is declared in, at

by Dave Nottage Email: Anonymous


How to retrieve the name of a unit that a class is declared in, at runtime
Download Details
FTP  download also available 0 bytes
CDN Login Required to Download. (You will be redirected to the login page if you click on the Download Link)
To download this, you must have registered:
A free membership

For Delphi, Version 1.0  to 5.0 25 downloads
Copyright: No significant restrictions


Size: 0 bytes
Updated on Tue, 22 May 2001 01:56:29 GMT
Originally uploaded on Tue, 22 May 2001 01:46:14 GMT
Description
To return the name of a unit that a class is declared in, such as a form, control, or any other class, use the GetTypeData method, which is declared in the TypInfo unit, eg:

uses
TypInfo;

procedure TAncestorForm.OnCreate(Sender: TObject);
var
TD: PTypeData;
begin
TD := GetTypeData(Self.ClassInfo);
if TD <> nil then
Label1.Caption := TD^.UnitName + '.pas';
end;

I've named the form class TAncestorForm as a demo that it can be used to show which unit descendant forms are defined in.

   Latest Comments  View All Add New

Move mouse over comment to see the full text

Could not retrieve comments. Please try again later.

Server Response from: ETNACDC03