[fpc-pascal] Case based on type

Mark Morgan Lloyd markMLl.fpc-pascal at telemetry.co.uk
Sat Mar 2 08:00:04 CET 2013


Marco van de Voort wrote:
> 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;

Thanks, detail noted.

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

[Opinions above are the author's, not those of his employers or colleagues]



More information about the fpc-pascal mailing list