[fpc-pascal] Case based on type
Marco van de Voort
marcov at stack.nl
Sat Mar 2 00:13:58 CET 2013
In our previous episode, Sven Barth said:
> === example end ===
>
> Alternatively if you don't need to check the hierarchy, but can live
> with an exact match you can do this:
>
> === example begin ===
>
> procedure checkLibrariesAndConnect(db: TSQLConnection);
> begin
> case LowerCase(db.ClassName) of
> // Note: .ClassName won't work here
> 'TPQConnection': ...;
> 'TIBConnection': ...;
> end;
> end;
var typ : TCLass;
begin
typ:=db.classtype; found:=false;
while not found and assigned(typ) do
begin
case lowercase(typ.classname)
.. // must set found=true on match or break.
end;
typ:=typ.classparent;
end;
More information about the fpc-pascal
mailing list