[fpc-devel] Re: CodeGear abandons Delphi.NET
Graeme Geldenhuys
graemeg.lists at gmail.com
Thu Nov 6 07:41:54 CET 2008
On Thu, Nov 6, 2008 at 8:18 AM, Alexander Klenin <klenin at gmail.com> wrote:
> 1) http://prismwiki.codegear.com/en/With_(keyword)
> but without 'matching' clause.
The following code is just confusing as hell...
with b: Button := new Button do
with c: Color := b.BackColor do begin
...
b.Text := 'Hello World';
self.Text := c.ToString;
...
end;
end;
> 1) 'case' by string and type http://prismwiki.codegear.com/en/Case_(keyword)
Did you not know that this is supported in FPC (for some time now).
;-) And it's not just limited to ordinal or string types.... I'll
share my code. We have been using this for some time in our projects.
:-)
Example usage:
case CaseObject(Action, [BackAction, ForwardAction]) of
0: BackAction.Enabled := FTreeViewAdapter.BackStack.Count > 0;
1: ForwardAction.Enabled := FTreeViewAdapter.ForwardStack.Count > 0;
end;
---------------------[ m2utils.pas ]-------------------------
// case statement support methods
function CaseObject(AObject: TObject; AObjectArray: array of
TObject): Integer;
function CaseClass(AClass: TClass; AClassArray: array of TClass):
Integer; overload;
function CaseClass(AObject: TObject; AClassArray: array of TClass):
Integer; overload;
function CaseGUID(GUID: TGUID; GUIDArray: array of TGUID): Integer;
function CaseInterface(AInterface: IInterface; AClassArray: array of
IInterface): Integer;
function CaseString(S: string; SArray: array of string): Integer;
function CasePointer(P: Pointer; PArray: array of Pointer): Integer;
{ Case statement support methods }
function CaseObject(AObject: TObject; AObjectArray: array of TObject): Integer;
var
Counter: Integer;
begin
Result := -1;
for Counter := 0 to Length(AObjectArray)-1 do
begin
if AObject = AObjectArray[Counter] then
begin
Result := Counter;
Exit; //==>
end;
end;
end;
function CaseClass(AClass: TClass; AClassArray: array of TClass): Integer;
var
Counter: Integer;
begin
Result := -1;
for Counter := 0 to Length(AClassArray)-1 do
begin
if AClass = AClassArray[Counter] then
begin
Result := Counter;
Exit; //==>
end;
end;
end;
function CaseClass(AObject: TObject; AClassArray: array of TClass): Integer;
begin
Result := CaseClass(AObject.ClassType, AClassArray);
end;
function CaseGUID(GUID: TGUID; GUIDArray: array of TGUID): Integer;
var
Counter: Integer;
begin
Result := -1;
for Counter := 0 to Length(GUIDArray)-1 do
begin
if IsEqualGUID(GUID, GUIDArray[Counter]) then
begin
Result := Counter;
Exit; //==>
end;
end;
end;
function CaseInterface(AInterface: IInterface; AClassArray: array of
IInterface): Integer;
var
Counter: Integer;
begin
Result := -1;
for Counter := 0 to Length(AClassArray)-1 do
begin
if AInterface = AClassArray[Counter] then
begin
Result := Counter;
Exit; //==>
end;
end;
end;
function CaseString(S: string; SArray: array of string): Integer;
var
Counter: Integer;
begin
Result := -1;
for Counter := 0 to Length(SArray)-1 do
begin
if S = SArray[Counter] then
begin
Result := Counter;
Exit; //==>
end;
end;
end;
function CasePointer(P: Pointer; PArray: array of Pointer): Integer;
var
Counter: Integer;
begin
Result := -1;
for Counter := 0 to Length(PArray)-1 do
begin
if P = PArray[Counter] then
begin
Result := Counter;
Exit; //==>
end;
end;
end;
-----------------------------[ end ]---------------------------
> 3) http://prismwiki.codegear.com/en/Exception_Handling#Combining_except_and_finally_blocks
>
Now that would be very handy!! Saves on typing and saves on indentation.
Regards,
- Graeme -
_______________________________________________
fpGUI - a cross-platform Free Pascal GUI toolkit
http://opensoft.homeip.net/fpgui/
More information about the fpc-devel
mailing list