Re: [fpc-pascal] Extending an enumeration

2010-07-20 Thread Thierry Coq

On 18/07/2010 20:56, Mark Morgan Lloyd wrote:
...
Yes, I was thinking that. However if the basic class was say a 
round-robin scheduler with phases rrQuiescent and rrInitialised and 
the descendant was say an HP comms protocol handler with additional 
phases hpReceivingPadding, hpReceivedSync and so on it would seem to 
be questionable practice to have to define all possible enumerated 
values in the basic class.



...
In this case, enumeration cannot be extended. If you look at it from an 
analysis point of view, you're implementing a state machine with an 
enumeration. If your state machine is extendable instead of fixed, and 
you want to add substates to it, then a possible implementation is to 
define a state class:


TSchedulerPhase = Class(TObject);

where the basic phases are defined as variables in the base class, and 
initialized in the initialization of the base module:

var
   spQuiescent: TSchedulerPhase;
   spInitialized: TSchedulerPhase;
Initialization
  spQuiescent := TSchedulerPhase.Create;
...

The descendent class can add other states, and compute other transitions.
This is a classic implementation of the state design pattern.

I hope this helps,
Thierry.
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal


[fpc-pascal] How to set a CORBA interface property (tkInterfaceRaw) through RTTI

2010-07-20 Thread Luiz Americo Pereira Camara

Hi,

I've managed to set a COM interface property (tkInterface) through RTTI 
using SetInterfaceProp.


But i could not find a way to set a CORBA interface property 
(tkInterfaceRaw) since SetInterfaceProp expects IUnknown.


In the attached example, when i try to use SetInterfaceProp i get the 
message "Incompatible type for arg no. 3: Got "IMyIntf", expected 
"IUnknown"".


Is there a way to set a CORBA interface property through RTTI?

Luiz

program bugIntfRTTI;

{$mode objfpc}{$H+}

{$Define USE_CORBA}

uses
  Classes, typinfo;

type

  {$ifdef USE_CORBA}
  {$INTERFACES CORBA}
  {$endif}

  IMyIntf = interface
procedure DoIt;
  end;


  {$ifdef USE_CORBA}
  TMyIntfImpl = class(TObject, IMyIntf)
procedure DoIt;
  end;
  {$else}
  TMyIntfImpl = class(TInterfacedObject, IMyIntf)
procedure DoIt;
  end;
  {$endif}


  TMyObj = class(TComponent)
  private
FIntf: IMyIntf;
procedure SetIntf(const Value: IMyIntf);
  published
property Intf: IMyIntf read FIntf write SetIntf;
  end;

procedure TMyObj.SetIntf(const Value: IMyIntf);
begin
  FIntf := Value;
  WriteLn('SetIntf: ' + hexStr(FIntf));
end;

procedure TMyIntfImpl.DoIt;
begin
  WriteLn('DoIt - ', {$ifdef USE_CORBA}'CORBA'{$else}'COM'{$endif});
end;

var
  Obj: TMyObj;
  Impl: IMyIntf;
  PropInfo: PPropInfo;

begin
  Impl := TMyIntfImpl.Create;
  Obj := TMyObj.Create(nil);

  PropInfo := GetPropInfo(PTypeInfo(Obj.ClassInfo), 'Intf');

  if PropInfo <> nil then
  begin
WriteLn('PropInfo Found: ' + GetEnumName(TypeInfo(TTypeKind), 
Integer(PropInfo^.PropType^.Kind)));
SetInterfaceProp(Obj, PropInfo, Impl);
Obj.Intf.DoIt;
  end
  else
WriteLn('PropInfo NOT Found');

  Obj.Destroy;
end.

___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal

Re: [fpc-pascal] Module or Plugin or similar howto implement?

2010-07-20 Thread Mark Morgan Lloyd

Reimar Grabowski wrote:

On Mon, 19 Jul 2010 17:13:15 +0200
Eduardo  wrote:


I'm developing an app and need to extend its functionality via external
modules or plugins. Currently i'm trying to do it using dll/so but
don't know if there are better methods to do implement it. 


I don't know if there are better methods, but I can say that the dll/so 
approach works quite well. At least it did for our project. It was written in 
C++ but I think it will work with pascal as well, if not better due to superior 
language. :)


It works, and a dll/so can be dressed up quite nicely as an object. The 
weakness is the lack of embedded description of the parameters etc. of 
each entry point.


--
Mark Morgan Lloyd
markMLl .AT. telemetry.co .DOT. uk

[Opinions above are the author's, not those of his employers or colleagues]
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal