kwang080897
asked on
Browsing a Record Structure
Is there a function that can return the contents of a record whithout knowing the types of variables and the names ???.
My Problem is that i have a lot of Record Stuctures, and I would like to have a generel function that can display an array of any of the Structures.
My Problem is that i have a lot of Record Stuctures, and I would like to have a generel function that can display an array of any of the Structures.
ASKER
Hi Epsylon !!
Thanks !!!
I am using Records because i have to mach some external records in a dll - so i guess i have to do it the hard way
What is the right way of grading an answer like this ?
Thanks !!!
I am using Records because i have to mach some external records in a dll - so i guess i have to do it the hard way
What is the right way of grading an answer like this ?
Someone has to submit an answer first. Do you consider my previous comment as an acceptable answer?
ASKER
Well i Guess im a.... Don't take no for an answer person - but if there really is no way then submit me an answer
Kwang
Kwang
Well, maybe other experts have something to add.....
If not I'll submit an answer later if that is ok with you
If not I'll submit an answer later if that is ok with you
ASKER
OK
ASKER
Thinking........
They say Delphi is Written in delphi......
In the Delphi Enviroment you type the Record name + .(dot) and a list of all the availiable Types in that Record pops up.
So if Delphi really is written in Delphi this Should be possible... or ?????
For a working answer I would be more that happy to Raise Points to 200
They say Delphi is Written in delphi......
In the Delphi Enviroment you type the Record name + .(dot) and a list of all the availiable Types in that Record pops up.
So if Delphi really is written in Delphi this Should be possible... or ?????
For a working answer I would be more that happy to Raise Points to 200
Kwang, that is something completely different. Delphi has a compiler/parser to do that and it goes far beyond this problem.
Then you are much quicker off by writing object instead of records. Maybe I could help you with that.
Epsylon.
Then you are much quicker off by writing object instead of records. Maybe I could help you with that.
Epsylon.
>In the Delphi Enviroment you type the Record name + .(dot)
>and a list of all the availiable Types in that Record pops
>up.
As Epsylon said, Delphi's editor achieves that by reading the source file (.pas). If there were no source files, than that couldn't be done.
The feature you're looking for is called RTTI, which means Run-Time Type Information, and is an information that can be gathered in runtime regarding a class.
Unfortunatly, RECORDS aren't classes, thus they don't have RTTI. My suggestion is to change the records into classes, so you can use RTTI to get information about these classes.
With RTTI you, can, for example, get information about all properties, types, etc, used by a class, which is precisely what you want.
Unfortunatly, unless you're willing to change the records into classes, the answer is "no".
Yours,
Alex
>and a list of all the availiable Types in that Record pops
>up.
As Epsylon said, Delphi's editor achieves that by reading the source file (.pas). If there were no source files, than that couldn't be done.
The feature you're looking for is called RTTI, which means Run-Time Type Information, and is an information that can be gathered in runtime regarding a class.
Unfortunatly, RECORDS aren't classes, thus they don't have RTTI. My suggestion is to change the records into classes, so you can use RTTI to get information about these classes.
With RTTI you, can, for example, get information about all properties, types, etc, used by a class, which is precisely what you want.
Unfortunatly, unless you're willing to change the records into classes, the answer is "no".
Yours,
Alex
What you are trying to do is called Run-Time Type Information or RTTI. RTTI is a mechanism by which the Delphi compiler can embed type information details into the compiled executable file for the program use at run time.
The compiler generates lists of information describing each published property of a component and stores that information in the exe file.
It allows stuff like this:
{$M+} // enables RTTI
type
TChessPiece = (Pawn, Rook, Knight, Bishop, Queen, King);
{$M-}
Procedure TForm1.ButtonClick(Sender: TObject);
var
I:Integer;
begin
for I := 0 to Ord(High(TChessPiece)) do
ListBox1.Items.Add(GetEnum Name(TypeI nfo(TChess Piece), I));
end;
This would yield the actual names (strings) in the listbox.
The compiler generates lists of information describing each published property of a component and stores that information in the exe file.
It allows stuff like this:
{$M+} // enables RTTI
type
TChessPiece = (Pawn, Rook, Knight, Bishop, Queen, King);
{$M-}
Procedure TForm1.ButtonClick(Sender:
var
I:Integer;
begin
for I := 0 to Ord(High(TChessPiece)) do
ListBox1.Items.Add(GetEnum
end;
This would yield the actual names (strings) in the listbox.
ASKER
Hi !!!
Hmmmmmmmmmmmmmmmmm it's sounds like a lot of work......
and Most important !
will i be able to pass the Object as a parameter to my Dll function instead of Records (i am using pre existing Dll's and I have defined my Record so that the match the Types in the Dll Header)
Hmmmmmmmmmmmmmmmmm it's sounds like a lot of work......
and Most important !
will i be able to pass the Object as a parameter to my Dll function instead of Records (i am using pre existing Dll's and I have defined my Record so that the match the Types in the Dll Header)
Never mind simonet beat me. Read his comment. Records to Classes, that's the ticket. By the way, a good RTTI reference is the Delphi Component Design by Danny Thorpe.
ASKER
Hi Calvin !!
Sorry - but i am working with Records - not classes
Sorry - but i am working with Records - not classes
ASKER
I Guess not !!!
Hi Epsylon !
I will grade you for your "No"
-------------------------- ---------- -----
Simonet and Calvinday !!
Thank for the good suggestion - but I Dont think RTTI is my sollution....
-------------------------- ---------- ---------- -----
Simonnet !!
I have seen your messages about "blacklists"
(this is what I hade about the Gradings - actually i feel everybody has been very helpfull. You and Calvinday have put some work in supplying me an answer - Still not an answer I can use in my case
So Am i beeing fair when grading Epsylon ?? )
Please Comment (Dont' wanna be blacklistet)
Hi Epsylon !
I will grade you for your "No"
--------------------------
Simonet and Calvinday !!
Thank for the good suggestion - but I Dont think RTTI is my sollution....
--------------------------
Simonnet !!
I have seen your messages about "blacklists"
(this is what I hade about the Gradings - actually i feel everybody has been very helpfull. You and Calvinday have put some work in supplying me an answer - Still not an answer I can use in my case
So Am i beeing fair when grading Epsylon ?? )
Please Comment (Dont' wanna be blacklistet)
Kwang, if you convert the records to classes (= objects) the records you have right now will be 'stored' inside the classes. So you can still pass the record to the DLL as a parameter. Of course the function in the DLL will not know about that class anymore.
I guess it will not be as difficult as you think but I don't know what your record look like of course, so it's difficult for me to judge it.
Epsylon.
I guess it will not be as difficult as you think but I don't know what your record look like of course, so it's difficult for me to judge it.
Epsylon.
Are you familiar with creating object?
Changing a record to class should be as simple as:
type
TRecord = record
A:integer;
B:integer;
end;
type
TRecord = class
A:integer;
B:integer;
end;
It does have the overhead of several functions and procedures. Am I correct?
type
TRecord = record
A:integer;
B:integer;
end;
type
TRecord = class
A:integer;
B:integer;
end;
It does have the overhead of several functions and procedures. Am I correct?
Kwang,
That thread wasn't about blacklists. It was about a few bad users out there who have no respect to the work that's
being done here. That doesn't apply to you, so don't worry.
>it's sounds like a lot of work......
not at all. It's actually very easy... easier than you think.
>but I Dont think RTTI is my sollution....
YEs, it is. There's no other way of getting information about (class) types. RTTI is the one and only solution.
>So Am i beeing fair when grading Epsylon ?? )
Sure you are!
Alex
That thread wasn't about blacklists. It was about a few bad users out there who have no respect to the work that's
being done here. That doesn't apply to you, so don't worry.
>it's sounds like a lot of work......
not at all. It's actually very easy... easier than you think.
>but I Dont think RTTI is my sollution....
YEs, it is. There's no other way of getting information about (class) types. RTTI is the one and only solution.
>So Am i beeing fair when grading Epsylon ?? )
Sure you are!
Alex
ASKER
Hi all !
A lot of my Records Structures are used as arrays.
Most of the Return values from the External Dll is Arrays of Record Structures...
Very Often one af the Parameters in the dll function return the size of the array - so if I chould do this i quess i would have to both have Classes and Record and then Translate it to a class after calling the Dll (to instantiate it) - Wouldent I ???? And then it gets complicated i think
kwang
A lot of my Records Structures are used as arrays.
Most of the Return values from the External Dll is Arrays of Record Structures...
Very Often one af the Parameters in the dll function return the size of the array - so if I chould do this i quess i would have to both have Classes and Record and then Translate it to a class after calling the Dll (to instantiate it) - Wouldent I ???? And then it gets complicated i think
kwang
kwang:
If you want to persist using records this can be done, though you will need to add extra information to your program so that it can determine how to process the record.
One way to do this would be to set up an enumeration which identifies each record type. Your function returning the records can just return a block of memory containing the record and the enumeration value that corresponds to that particular record type. You then use this enumeration to look up information about the record. In effect you are supplying your own RTTI for the record. This way you can still code it using a fairly small piece of code.
What yo do think?
Cheers,
Raymond.
If you want to persist using records this can be done, though you will need to add extra information to your program so that it can determine how to process the record.
One way to do this would be to set up an enumeration which identifies each record type. Your function returning the records can just return a block of memory containing the record and the enumeration value that corresponds to that particular record type. You then use this enumeration to look up information about the record. In effect you are supplying your own RTTI for the record. This way you can still code it using a fairly small piece of code.
What yo do think?
Cheers,
Raymond.
ASKER
Hi Raymond !!
It is very important that the Records stays the same size (Had Enough trouble just Padding the Structure to make it fit with the C Structure)
All !!
Actually when i arsked this question - I was hoping to find a way to handle Records in the future - but i now realize that is is not possible (with records).
In the project I'm working on it's really not that big a problem - I just thought that it would be nice if it was possible.
So again Thanks all for trying to help !
Raymond !!! Please Submit and I will Grade You
It is very important that the Records stays the same size (Had Enough trouble just Padding the Structure to make it fit with the C Structure)
All !!
Actually when i arsked this question - I was hoping to find a way to handle Records in the future - but i now realize that is is not possible (with records).
In the project I'm working on it's really not that big a problem - I just thought that it would be nice if it was possible.
So again Thanks all for trying to help !
Raymond !!! Please Submit and I will Grade You
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Oh - just thought I'd note that the records wouldn't have to be the same size, the function could even just return a pointer to a particular record. The point being that the caller knows how to deal with it through the extra information give the program...
Cheers,
Raymond.
Cheers,
Raymond.
The other way is by defining each member of all records as Variant or TVarRec.
Cheers,
Epsylon.