Конференция "KOL" » вопсрос по PStrListEx [Delphi, Windows]
 
  • RusSun © (28.11.12 18:47) [0]
    Доброе время суток. (WinXP,Delphi7)
    пытаюсь перевести следующий кусок кода с VCL на KOL.
    const

    vlist = 'первый, второй, третий';

    var VL: TStringList;

    procedure SetValues(VL : TStringList; S: String);

    var I : Integer;
    begin
    VL.CommaText := S;

    for I := 0 to VL.Count-1 do
      VL.Objects[I] := Pointer(I);
    VL.Sorted := True;

    end;

    function GetValueIndex(VL : TStringList; Match: String): Integer;

    begin
    Result := VL.IndexOf(Match);
    if Result >= 0 then
      Result := Integer(VL.Objects[Result]);
    end;

    procedure TForm1.Button1Click(Sender: TObject);

    begin
    case GetValueIndex(VL, Edit1.Text) of
      -1: ; //не найден
       0: Caption := '0';
       1: Caption := '1';
       2: Caption := '2';
    end;
    end;

    initialization
    VL := TStringList.Create;
    SetValues(VL, vlist);

    finalization
    VL.Free;

    end.


    получилось следующее
    public
     procedure Button1Click(Sender: PObj);
     procedure KOLForm1Close(Sender: PObj; var Accept: Boolean);
    end;
    const vlist = 'первый, второй, третий';
    var
    Form1: PForm1;
    VL: PStrListEx;
    // TStrListEx = object( TStrList )
     {* Extended string list object. Has additional capability to associate
        numbers or objects with string list items. }


    procedure SetValues(VL :PStrListEx; S: String);
    //var I : Integer;
    begin
    VL.Text := S;
    //for I := 0 to VL.Count-1 do
    //  VL.Objects[I] := Pointer(I);

       VL.AddObject('первый', 0);
        VL.AddObject('второй', 1);
         VL.AddObject('третий', 2);

    //VL.Sort(True);
    end;
    function GetValueIndex(VL :PStrListEx; Match: String): Integer;

    begin
    Result := VL.IndexOf(Match);
    if Result >= 0 then
      Result := Integer(VL.Objects[Result]);
    end;

    procedure TForm1.Button1Click(Sender: PObj);
    begin
    case GetValueIndex(VL,'третий') of
      -1: {не найден} ;
       0: Form1.Form.Caption := '0';
       1: Form1.Form.Caption := '1';
       2: Form1.Form.Caption := '2';
    end;

    end;

    procedure NewForm1(var Result: PForm1; AParent: PControl);
    begin
    New(Result, Create);
    with Result^ do
    begin
      Form := NewForm(AParent, 'Project1');
      Form.Add2AutoFree(Result);
      Applet := Form;
      VL := NewStrListEx;
      SetValues(VL, vlist);
      //Form.Add2AutoFree(VL);
      Form.SetClientSize(320, 240).CenterOnParent;
     
       Button1 := NewButton( Form, 'Click' ).SetPosition( 22, 8 ).SetSize( 0, 26 );
           {$IFDEF UNICODE_CTRLS}
       Button1.SetUnicode(TRUE);
           {$ENDIF UNICODE_CTRLS}
       Button1.OnClick := Button1Click;
       Form.OnClose := KOLForm1Close;
    end;
    end;
    procedure TForm1.KOLForm1Close(Sender: PObj; var Accept: Boolean);
    begin
    VL.Free
    end;
    begin
    NewForm1(Form1, nil);
    Run(Form1.Form);
    end.



    Забуксовал на этом моменте.
    for I := 0 to VL.Count-1 do
      VL.Objects[I] := Pointer(I);


    прошу помощи)
    Вариант ввода в ручную
    VL.AddObject('первый', 0);
        VL.AddObject('второй', 1);
         VL.AddObject('третий', 2); не кажется лучшим решением
  • Дмитрий К © (29.11.12 18:17) [1]
    procedure SetValues(VL :PStrListEx; S: String);
    var I : Integer;
    begin
     while StrReplace(S, ', ', #13#10) do;
     VL.Text := S;
     for I := 0 to VL.Count-1 do
       VL.Objects[I] := Pointer(I);
    end;

  • RusSun © (30.11.12 18:15) [2]
    VL.Objects[I] := Pointer(I);

    [Pascal Error] ...(328): E2010 Incompatible types: 'Cardinal' and 'Pointer'
  • Дмитрий К © (30.11.12 18:40) [3]
    VL.Objects[I] := I;
  • RusSun © (01.12.12 21:27) [4]
    Большое спасибо. Вопрос решен.
 
Конференция "KOL" » вопсрос по PStrListEx [Delphi, Windows]
Есть новые Нет новых   [118684   +12][b:0][p:0.003]