Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-pascal / 2002-01

RTTI

4 messages · 4 people ·

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Jean-Pierre PLANAS

Hello

Here a piece of delphi code i want to port to fpc.

     uses TypInfo;
     type
TJour=(jrLundi,jrMardi,jrMercredi,jrJeudi,jrVendredi,jrSamedi,jrDimanche);
     procedure TForm1.btnClick(Sender: TObject);
     begin
     ShowMessage(IntToStr(GetEnumValue(TypeInfo(TJour),'jrMardi')));
     ShowMessage(GetEnumName(TypeInfo(TJour),1));
     end;

I saw that fpc have a typeInfo.pp unit with GetEnumValue and GetEnumName functions.
But i can use them like with delphi.

     Writeln(GetEnumValue(???(TJour),'jrMardi'));
     Writeln(GetEnumName(???(TJour),1));

What can replace ??? ?

Sybaris.

Michael Van Canneyt
to Jean-Pierre PLANAS
Jean-Pierre PLANAS wrote 23 lines
Hello Here a piece of delphi code i want to port to fpc. uses TypInfo; type TJour=(jrLundi,jrMardi,jrMercredi,jrJeudi,jrVendredi,jrSamedi,jrDimanche); procedure TForm1.btnClick(Sender: TObject); begin ShowMessage(IntToStr(GetEnumValue(TypeInfo(TJour),'jrMardi'))); ShowMessage(GetEnumName(TypeInfo(TJour),1)); end; I saw that fpc have a typeInfo.pp unit with GetEnumValue and GetEnumName functions. But i can use them like with delphi. Writeln(GetEnumValue(???(TJour),'jrMardi')); Writeln(GetEnumName(???(TJour),1)); What can replace ??? ?

Version 1.1 contains the TypInfo call.

For version 1.0.x the following workaround can be done;
Type
  {$M+} // VERY Important !!
  TMyEnumClass = Class
    FMyEnym : TJour;
  Published
    property MyEnum : TJour Read GMyEnum Write FMyEnum;
  end;

Now you can do:

Var
  PI : PPropInfo;
  TI : PtypeInfo;
// Store TI in global variable.
begin
PI:=GetPropInfo(TMyEnuMClass,'MyEnum');
If PINil then
  begin
  TI:=PI^.PropType;
  If TI=Nil then
    begin
    writeln(stderr,'Could not find type information for Myenum');
    Halt(1)
    end;
  end;

The TI can now be used in calls to GetEnumValue:

IntToStr(GetEnumValue(TI,'jrMardi'))
GetEnumName(TI,1);

If you have multiple enumeration types, store them in 1 class, and repeat the above for each type, storing the PTypeInfo pointers in variables.

Michael.

Vit Kavan
to Michael Van Canneyt

Hi,

I've tried to compile some of my VST plugins under FPC and they don't work (master applications don't recognize them), they work perfectly when compiled by Delphi.

VST Plugins are virtual musical instruments & audio effect, standard defined by Steinberg. Technically it's a DLL exporting 1 function "main".

Should I try some compiler switches? Any other ideas?

Thanx, VTech

______________________________________________________________________ Seznam Prace - Hledate praci nebo menite zamestnani? http://prace.seznam.cz

Kanzelsberger Pavel

Try -WRD, FPC will use DEFFILE to export functions. I encountered several problems with DLLs too but this seems to solve the problem with FPC 1.0.4

Pavel Kanzelsberger

Earlier message 23 lines
-----Original Message----- From: Vit Kavan Sent: Monday, January 21, 2002 3:47 PM To: Subject: [fpc-pascal]VST PlugIns don't work Hi, I've tried to compile some of my VST plugins under FPC and they don't work (master applications don't recognize them), they work perfectly when compiled by Delphi. VST Plugins are virtual musical instruments & audio effect, standard defined by Steinberg. Technically it's a DLL exporting 1 function "main". Should I try some compiler switches? Any other ideas? Thanx, VTech ______________________________________________________________________ Seznam Prace - Hledate praci nebo menite zamestnani? http://prace.seznam.cz