Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Browsing a Record Structure

Posted on 1999-07-08
23
Medium Priority
?
205 Views
Last Modified: 2010-04-06
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.
0
Comment
Question by:kwang080897
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 9
  • 6
  • 3
  • +2
23 Comments
 
LVL 13

Expert Comment

by:Epsylon
ID: 1387148
That can not be done. One way to do that is by not using Records but by using Objects. The object contains the record and the necessary functions to work with that record.

The other way is by defining each member of all records as Variant or TVarRec.


Cheers,

Epsylon.
0
 

Author Comment

by:kwang080897
ID: 1387149
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 ?




0
 
LVL 13

Expert Comment

by:Epsylon
ID: 1387150
Someone has to submit an answer first. Do you consider my previous comment as an acceptable answer?
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 

Author Comment

by:kwang080897
ID: 1387151
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




 
0
 
LVL 13

Expert Comment

by:Epsylon
ID: 1387152
Well, maybe other experts have something to add.....
If not I'll submit an answer later if that is ok with you
0
 

Author Comment

by:kwang080897
ID: 1387153
OK
0
 

Author Comment

by:kwang080897
ID: 1387154
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

0
 
LVL 13

Expert Comment

by:Epsylon
ID: 1387155
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.


0
 
LVL 15

Expert Comment

by:simonet
ID: 1387156
>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


0
 
LVL 2

Expert Comment

by:CalvinDay
ID: 1387157
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(GetEnumName(TypeInfo(TChessPiece), I));
end;

This would yield the actual names (strings) in the listbox.

0
 

Author Comment

by:kwang080897
ID: 1387158
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)



0
 
LVL 2

Expert Comment

by:CalvinDay
ID: 1387159
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.
0
 

Author Comment

by:kwang080897
ID: 1387160
Hi Calvin !!

  Sorry - but i am working with Records - not classes
 
0
 

Author Comment

by:kwang080897
ID: 1387161
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)

0
 
LVL 13

Expert Comment

by:Epsylon
ID: 1387162
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.
0
 
LVL 13

Expert Comment

by:Epsylon
ID: 1387163
Are you familiar with creating object?
0
 
LVL 2

Expert Comment

by:CalvinDay
ID: 1387164
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?

0
 
LVL 15

Expert Comment

by:simonet
ID: 1387165
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




0
 

Author Comment

by:kwang080897
ID: 1387166
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

0
 
LVL 12

Expert Comment

by:rwilson032697
ID: 1387167
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.
0
 

Author Comment

by:kwang080897
ID: 1387168
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

0
 
LVL 12

Accepted Solution

by:
rwilson032697 earned 200 total points
ID: 1387169
Here it is as an answer...

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.

Cheers,

Raymond.
0
 
LVL 12

Expert Comment

by:rwilson032697
ID: 1387170
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.

0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses

664 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question