[fpc-devel] Ability to handle instance pointers as ordinal type.

thaddy at thaddy.com thaddy at thaddy.com
Sun Feb 21 11:37:38 CET 2016


I have been pondering with that idea ever since the implementation of 
strings for case.
This morning I remembered again why it may be useful.
Consider this code vs the alternative I suggest.
  Plz. do not value the code, it is just copied from the forum and 
frankly not the point but an illustration:

 1.
    procedure TFrame00.ComboBoxChanged(Sender: TObject);
 2.
    Var
 3.
       x : TComboBox;
 4.
    begin
 5.
    If (Sender Is TComboBox) Then
 6.
    begin
 7.
       x := (Sender As TComboBox);
 8.
 9.
    case x.Name of
10.
    'ComboBox01':if x.ItemIndex = -1 then x.ItemIndex := PrjIndex else
11.
    begin
12.
    end;
13.
    'ComboBox02':if x.ItemIndex = -1 then x.ItemIndex := HubIndex else
14.
    begin
15.
    end;
16.
    'ComboBox03':if x.ItemIndex = -1 then x.ItemIndex := RimIndex else
17.
    begin
18.
    end;
19.
    'ComboBox04':if x.ItemIndex = -1 then x.ItemIndex := SpkIndex else
20.
    begin
21.
    end;
22.
    end;
23.
    End;
24.
    end;
25.
26.

  Now how much nicer it would be if you could write someting along the 
lines of:

 1.
    procedure TFrame00.ComboBoxChanged(Sender: TObject);
 2.
    begin
 3.
    If Sender Is TComboBox Then
 4.
    case TCombobox(sender) of
 5.
         Combobox1:;
 6.
         ComboBox2:;
 7.
         ComboBox3:;
 8.
    end;
 9.
    end;

In other words, use the instance pointer as an ordinal value.
It looks a lot more logical but as it stands it is of course invalid syntax.
Is it possible to implement?
If so, has it any value? To me at least it looks feasable and less like 
syntactic sugar than some features.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freepascal.org/pipermail/fpc-devel/attachments/20160221/593a71fa/attachment.html>


More information about the fpc-devel mailing list