Results 1 to 14 of 14

Thread: TMemo and TComboBox

  1. #1
    Join Date
    Aug 2007
    Location
    in a random little world
    Posts
    5,778
    Mentioned
    0 Post(s)
    Quoted
    7 Post(s)

  2. #2
    Join Date
    Nov 2007
    Location
    Chile
    Posts
    1,901
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    For Memo:
    Memo1.Text or Memo1.Lines.Text

    For ComboBox:
    ComboBox1.Text


  3. #3
    Join Date
    Aug 2007
    Location
    in a random little world
    Posts
    5,778
    Mentioned
    0 Post(s)
    Quoted
    7 Post(s)

    Default

    hmmm...
    PlayerFood is a TComboBox but when i do this
    SCAR Code:
    writeln(PlayerFood.text);
    i get this
    Code:
    [Runtime Error] : Exception: Access violation at address 696C7053. Read of address 696C7053 in line 820 in script C:\Users\Thomas\Desktop\form.scar
    :/

    ~shut

    EDIT: never mind i fixed it
    but is it a TStringArray that is returned from a TMemo or a String?
    Last edited by Shuttleu; 05-10-2009 at 12:30 AM.

  4. #4
    Join Date
    Nov 2007
    Location
    Chile
    Posts
    1,901
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    Memo.Text or Lines.Text returns the entire text in a string. The problem with them is, that there aren't lines because they are showed as a character(#32). To get the lines I think it's Memo.Lines[0].


  5. #5
    Join Date
    Aug 2007
    Location
    in a random little world
    Posts
    5,778
    Mentioned
    0 Post(s)
    Quoted
    7 Post(s)

    Default

    thank you for your help soo far
    but one last thing
    it doesnt work if i do
    SCAR Code:
    GetArrayLength(Memo.Lines)
    it says
    Code:
    Line 26: [Error] (16780:52): Variable Expected in script C:\Users\Thomas\Desktop\form.scar
    ugh...
    this is the last thing i need to know

    ~shut

  6. #6
    Join Date
    Feb 2006
    Location
    Helsinki, Finland
    Posts
    1,395
    Mentioned
    30 Post(s)
    Quoted
    107 Post(s)

    Default

    SCAR Code:
    Memo.Lines.Count;

  7. #7
    Join Date
    May 2008
    Posts
    1,345
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    You could explode the result of Memo.Lines.Text using character #32 couldn't you?

    ~Sandstorm

  8. #8
    Join Date
    Feb 2006
    Location
    Helsinki, Finland
    Posts
    1,395
    Mentioned
    30 Post(s)
    Quoted
    107 Post(s)

    Default

    SCAR Code:
    var
      form: TForm;
      memo: TMemo;
      button: TButton;

    procedure reportMemoLines(Sender: TObject);
    var
      i, miC: Integer;
    begin
      ClearDebug;
      ClearReport;
      miC:= memo.Lines.Count;
      AddToReport('Total Lines: ' + IntToStr(miC));
      if(miC > 0)then
        for i:= 0 to (miC - 1) do
          WriteLn('Line ' + IntToStr(i) + ': ' + memo.Lines.Strings[i])
      else
        WriteLn('Memo is empty.');
    end;

    function buildForm: Boolean;
    begin
      form:= CreateForm;
      with form do
      begin
        SetBounds(0, 0, 500, 400);
        Position:= poScreenCenter;
        BorderStyle:= bsSingle;
        BorderIcons:= [biSystemMenu, biMinimize];
      end;
      memo:= TMemo.Create(form);
      with memo do
      begin
        Parent:= form;
        SetBounds(5, 5, 484, 332);
      end;
      button:= TButton.Create(form);
      with button do
      begin
        Parent:= form;
        SetBounds(220, 342, 50, 21);
        OnClick:= @reportMemoLines;
      end;
      Result:= (form.ShowModal = mrOK);
    end;

    function loadForm: Variant;
    var
      v: TVariantArray;
    begin
      Result:= ThreadSafeCall('buildForm', v);
    end;

    begin
      loadForm;
      FreeForm(form);
    end.

    Edit: Oh by the way, the type that is holding memo lines is actually TStrings, so if you want TStringArray of the lines, I have got a small workaround for doing that...

    SCAR Code:
    var
      form: TForm;
      memo: TMemo;
      button: TButton;

    function TStringsToTStringArray(strings: TStrings): TStringArray;
    var
      i, h: Integer;
    begin
      h:= strings.Count;
      SetArrayLength(Result, h);
      for i:= 0 to (h - 1) do
        Result[i]:= strings[i];
    end;

    procedure reportMemoLines(Sender: TObject);
    var
      i, miC: Integer;
      TSA: TStringArray;
    begin
      ClearDebug;
      miC:= memo.Lines.Count;
      if(miC > 0)then
      begin
        TSA:= TStringsToTStringArray(memo.Lines);
        for i:= 0 to (miC - 1) do
        begin
          WriteLn('memo.Lines.Strings[' + IntToStr(i) + ']: ' + memo.Lines.Strings[i])
          WriteLn('TSA[' + IntToStr(i) + ']: ' + TSA[i]);
          WriteLn('');
        end;
      end else
        WriteLn('memo = Empty');
    end;

    function buildForm: Boolean;
    begin
      form:= CreateForm;
      with form do
      begin
        SetBounds(0, 0, 500, 400);
        Position:= poScreenCenter;
        BorderStyle:= bsSingle;
        BorderIcons:= [biSystemMenu, biMinimize];
      end;
      memo:= TMemo.Create(form);
      with memo do
      begin
        Parent:= form;
        SetBounds(5, 5, 484, 332);
      end;
      button:= TButton.Create(form);
      with button do
      begin
        Parent:= form;
        SetBounds(220, 342, 50, 21);
        OnClick:= @reportMemoLines;
      end;
      Result:= (form.ShowModal = mrOK);
    end;

    function loadForm: Variant;
    var
      v: TVariantArray;
    begin
      Result:= ThreadSafeCall('buildForm', v);
    end;

    begin
      loadForm;
      FreeForm(form);
    end.

    => function TStringsToTStringArray.
    Last edited by Janilabo; 05-10-2009 at 02:57 AM.

  9. #9
    Join Date
    Aug 2007
    Location
    in a random little world
    Posts
    5,778
    Mentioned
    0 Post(s)
    Quoted
    7 Post(s)

    Default

    Quote Originally Posted by Janilabo View Post
    SCAR Code:
    var
      form: TForm;
      memo: TMemo;
      button: TButton;

    procedure reportMemoLines(Sender: TObject);
    var
      i, miC: Integer;
    begin
      ClearDebug;
      ClearReport;
      miC:= memo.Lines.Count;
      AddToReport('Total Lines: ' + IntToStr(miC));
      if(miC > 0)then
        for i:= 0 to (miC - 1) do
          WriteLn('Line ' + IntToStr(i) + ': ' + memo.Lines.Strings[i])
      else
        WriteLn('Memo is empty.');
    end;

    function buildForm: Boolean;
    begin
      form:= CreateForm;
      with form do
      begin
        SetBounds(0, 0, 500, 400);
        Position:= poScreenCenter;
        BorderStyle:= bsSingle;
        BorderIcons:= [biSystemMenu, biMinimize];
      end;
      memo:= TMemo.Create(form);
      with memo do
      begin
        Parent:= form;
        SetBounds(5, 5, 484, 332);
      end;
      button:= TButton.Create(form);
      with button do
      begin
        Parent:= form;
        SetBounds(220, 342, 50, 21);
        OnClick:= @reportMemoLines;
      end;
      Result:= (form.ShowModal = mrOK);
    end;

    function loadForm: Variant;
    var
      v: TVariantArray;
    begin
      Result:= ThreadSafeCall('buildForm', v);
    end;

    begin
      loadForm;
      FreeForm(form);
    end.

    Edit: Oh by the way, the type that is holding memo lines is actually TStrings, so if you want TStringArray of the lines, I have got a small workaround for doing that...

    SCAR Code:
    var
      form: TForm;
      memo: TMemo;
      button: TButton;

    function TStringsToTStringArray(strings: TStrings): TStringArray;
    var
      i, h: Integer;
    begin
      h:= strings.Count;
      SetArrayLength(Result, h);
      for i:= 0 to (h - 1) do
        Result[i]:= strings[i];
    end;

    procedure reportMemoLines(Sender: TObject);
    var
      i, miC: Integer;
      TSA: TStringArray;
    begin
      ClearDebug;
      miC:= memo.Lines.Count;
      if(miC > 0)then
      begin
        TSA:= TStringsToTStringArray(memo.Lines);
        for i:= 0 to (miC - 1) do
        begin
          WriteLn('memo.Lines.Strings[' + IntToStr(i) + ']: ' + memo.Lines.Strings[i])
          WriteLn('TSA[' + IntToStr(i) + ']: ' + TSA[i]);
          WriteLn('');
        end;
      end else
        WriteLn('memo = Empty');
    end;

    function buildForm: Boolean;
    begin
      form:= CreateForm;
      with form do
      begin
        SetBounds(0, 0, 500, 400);
        Position:= poScreenCenter;
        BorderStyle:= bsSingle;
        BorderIcons:= [biSystemMenu, biMinimize];
      end;
      memo:= TMemo.Create(form);
      with memo do
      begin
        Parent:= form;
        SetBounds(5, 5, 484, 332);
      end;
      button:= TButton.Create(form);
      with button do
      begin
        Parent:= form;
        SetBounds(220, 342, 50, 21);
        OnClick:= @reportMemoLines;
      end;
      Result:= (form.ShowModal = mrOK);
    end;

    function loadForm: Variant;
    var
      v: TVariantArray;
    begin
      Result:= ThreadSafeCall('buildForm', v);
    end;

    begin
      loadForm;
      FreeForm(form);
    end.

    => function TStringsToTStringArray.
    thank you for your solution but i find that this works just as well
    instead of using
    SCAR Code:
    Lines:= GetArrayLength(memo.Lines)
    i used
    SCAR Code:
    Lines:= memo.Lines.Count
    thanks for your help

    ~shut

  10. #10
    Join Date
    Feb 2006
    Location
    Helsinki, Finland
    Posts
    1,395
    Mentioned
    30 Post(s)
    Quoted
    107 Post(s)

    Default

    No problem mate, just glad you got everything working!

    -Jani

  11. #11
    Join Date
    Aug 2007
    Location
    in a random little world
    Posts
    5,778
    Mentioned
    0 Post(s)
    Quoted
    7 Post(s)

  12. #12
    Join Date
    Feb 2006
    Location
    Helsinki, Finland
    Posts
    1,395
    Mentioned
    30 Post(s)
    Quoted
    107 Post(s)

    Default

    SCAR Code:
    function TStringArrayToTStrings(TSA: TStringArray): TStrings;
    var
      i, h: Integer;
    begin
      Result:= TStringList.Create;
      h:= High(TSA);
      for i:= 0 to h do
        Result.Append(TSA[i]);
    end;

    var
      T: TStrings;
      i, iC: Integer;

    begin
      T:= TStringArrayToTStrings(['Test1', 'Test2', 'Test3']);
      iC:= T.Count;
      for i:= 0 to (iC - 1) do
        WriteLn(T.Strings[i]);
      T.Free;
    end.
    It would be something like that...

    That was a harder one, haha..

  13. #13
    Join Date
    Aug 2007
    Location
    in a random little world
    Posts
    5,778
    Mentioned
    0 Post(s)
    Quoted
    7 Post(s)

  14. #14
    Join Date
    Feb 2006
    Location
    Helsinki, Finland
    Posts
    1,395
    Mentioned
    30 Post(s)
    Quoted
    107 Post(s)

    Default

    Change the 'TString' to either 'TStrings' or 'TStringList', TStringList is a better choice, though.

    I google'd a bit about TStrings, and it seems like it has some problems that has been fixed for TStringList.

    -Jani

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •