[New Programmer] Some questions lazarus / 9-Editor ---------------------------------------------------------------------- fiqs · 2011-03-23 19:11 *SOLVED* 1. How do I delete a certain line from a .txt file? 2. How do I update the displayed text of a Memo? Like, I have one Memo that displays the text from a .txt file, them I edit the file and add in the end one new line, but the Memo doesn't show that new line. I'd like to make one "Update" button. *SOLVED* 3. I want to make a program with 3 different forms(e.g. A calculator with 3 tabs, one for add, the other for substract and the last one for multiply, just a example), how can I change from 1 form to the other one? I've tried making 3 radio buttons, each one for a tab, but I had some problems(I could change from the first to the second/third, but couldn't change from the second to the first/third or from the third to the first/second, used the "Form.Show" and the "Form.Hide" commands). Why I couldn't change the tabs? Because, when I tried to add the "Form.Show"/"Form.Hide" commands in the second or in the third tabs, I get the following error: Code: [Select]unit2.pas(38,20) Error: Identifier not found "TfrmAdic" unit2.pas(40,1) Fatal: There were 2 errors compiling module, stopping TfrmAdic is one of the forms, and I've already tried to add "frmAdic: TfrmAdic;" in var, but when I do this, I get this error: Code: [Select]unit2.pas(38,20) Error: Identifier not found "TfrmAdic" unit2.pas(38,20) Error: Error in type definition unit2.pas(40,1) Fatal: There were 2 errors compiling module, stopping *SOLVED* 4. How do I work with Combo boxes? Like, I have one combo box with every month, but how can I know what is the month that the person choose? *SOLVED* 5. How can I add both the ScrollBars in one Memo? I've already tried "ssAutoBoth" and "ssBoth". *SOLVED* 6. Can I learn Pascal/Lazarus with Delphi-based tutorials/guides/etc.? Is there any differences? I'm new with programming and Lazarus, as you can see. Thanks, and what a great community Lazarus has Edit.: Thanks typo and TurboRascal for the great help ---------------------------------------------------------------------- typo · 2011-03-23 19:17 What OS and Lazarus version are you using? ---------------------------------------------------------------------- fiqs · 2011-03-23 19:19 Oh, sorry. I'm using Windows XP SP3 with Lazarus IDE v0.9.28.2 beta. ---------------------------------------------------------------------- typo · 2011-03-23 19:34 4. How do I work with Combo boxes? Like, I have one combo box with every month, but how can I know what is the month that the person choose?      The chosen item should appear as value of the property Text. 5. How can I add both the ScrollBars in one Memo? I've already tried "ssAutoBoth" and "ssBoth".      Any of these should do the job. 6. Can I learn Pascal/Lazarus with Delphi-based tutorials/guides/etc.? Is there any differences?      Yes, you can learn so. 1. How do I delete a certain line from a .txt file?      You could load it on a TStringList, delete a specified line and then save it. 2. How do I update the displayed text of a Memo? Like, I have one Memo that displays the text from a .txt file, them I edit the file and add in the end one new line, but the Memo doesn't show that new line. I'd like to make one "Update" button.      You simply need to reload the file on the TMemo. ---------------------------------------------------------------------- fiqs · 2011-03-23 19:41 Quote from: typo on March 23, 2011, 08:34:18 pm5. How can I add both the ScrollBars in one Memo? I've already tried "ssAutoBoth" and "ssBoth".      Any of these should do the job. Yeah, these should do the job, but it doesn't. Don't know why, but it just show the text left in the following line. Also, I noticed the "LazarusBrasil.Org" in your signature, and I'm also a brazilian. If you want you can talk with me in portuguese, don't know if it is against the rules of this forum. ---------------------------------------------------------------------- typo · 2011-03-23 19:48 Quotebut it doesn't. Don't know why, but it just show the text left in the following line. Set Wordwrap property to false. Whenever possible, use English. ---------------------------------------------------------------------- fiqs · 2011-03-23 19:55 Quote from: typo on March 23, 2011, 08:48:28 pmQuotebut it doesn't. Don't know why, but it just show the text left in the following line. Set Wordwrap property to false. Whenever possible, use English. Oh yeah, it worked, thanks And Ok, I think I can speak with English. Any suggestion about the other questions? ---------------------------------------------------------------------- typo · 2011-03-23 20:06 Please have a look at the previous post again, I have edited it. ---------------------------------------------------------------------- TurboRascal · 2011-03-23 20:28 3. Show some code and someone will tell you what you did wrong. At least paste the code which is source of your listed errors, that is class declaration of your form and the code block where you call Show method on your form. 6. Yes you can, and there are differences, but it can help you nonetheless. I found Delphi books quite helpful. ---------------------------------------------------------------------- fiqs · 2011-03-23 21:47 Quote from: typo on March 23, 2011, 08:34:18 pm1. How do I delete a certain line from a .txt file?      You could load it on a TStringList, delete a specified line and then save it. 2. How do I update the displayed text of a Memo? Like, I have one Memo that displays the text from a .txt file, them I edit the file and add in the end one new line, but the Memo doesn't show that new line. I'd like to make one "Update" button.      You simply need to reload the file on the TMemo. 1. Sorry but I didn't get the point, can you give me an example, please? 2. You mean like this? Code: [Select]Memo1.Lines.LoadFromFile('C:\textfile.txt')I've already tried that, but it didn't work. @TurboRascal 3. Ok, let's go. Code: [Select]unit Unit2; {$mode objfpc}{$H+} interface uses   Classes, SysUtils, FileUtil, LResources, Forms, Controls, Graphics, Dialogs,   StdCtrls, Unit3, Buttons, ExtCtrls, ColorBox, ComCtrls, ButtonPanel, ExtDlgs,   Menus, Process; type   { TfrmComp }   TfrmComp = class(TForm)     BtnAdicionar: TButton;     BtnSair: TButton;     GroupBox1: TGroupBox;     Label1: TLabel;     lblCopyright: TLabel;     Memo1: TMemo;     rBtnAdic: TRadioButton;     rBtnComp: TRadioButton;     rBtnInfo: TRadioButton;     procedure BtnAdicionarClick(Sender: TObject);     procedure BtnSairClick(Sender: TObject);     procedure rBtnAdicChange(Sender: TObject);     procedure rBtnInfoChange(Sender: TObject);   private     { private declarations }   public     { public declarations }   end; var   frmComp: TfrmComp;   //frmAdic: TfrmAdic; implementation { TfrmComp } procedure TfrmComp.BtnAdicionarClick(Sender: TObject); begin   Memo1.Lines.LoadFromFile('C:\comp.txt') end; procedure TfrmComp.BtnSairClick(Sender: TObject); begin   Application.Terminate; end; procedure TfrmComp.rBtnAdicChange(Sender: TObject); begin  // frmComp.Hide;  // frmAdic.Show; end; procedure TfrmComp.rBtnInfoChange(Sender: TObject); begin end; initialization   {$I unit2.lrs} end.I'm trying to do one kind of "appointment book"(or an agenda) for students. This is the second form, the first is working fine(I can change from the first to second and from the first to the third), but the problem is with the second and the third. ---------------------------------------------------------------------- typo · 2011-03-23 22:22 Code: [Select]var    sl :TStringList;  begin    sl := TStringList.Create;    try      sl.LoadFromFile('C:\textfile.txt');      sl.Delete(0);      sl.SaveToFile('C:\textfile.txt');    finally      sl.Free;    end;  end; ---------------------------------------------------------------------- fiqs · 2011-03-23 22:44 Quote from: typo on March 23, 2011, 11:22:16 pmCode: [Select]var    sl :TStringList;  begin    sl := TStringList.Create;    try      sl.LoadFromFile('C:\textfile.txt');      sl.Delete(0);      sl.SaveToFile('C:\textfile.txt');    finally      sl.Free;    end;  end;        Oh, now I got it, thanks! But, would you mind explain me what does this sl.Free means? I've already seen it in other codes, but still not understanding. ---------------------------------------------------------------------- TurboRascal · 2011-03-23 23:08 Where did you define TfrmAdic class? In another unit? If so, why did you declare frmAdic in this unit? If that's the problem you should add the unit where frmAdic is declared to the uses statement in the interface section of this unit, if not already done (is it possibly "unit3" there?)... If so, simply removing the frmAdic var declaration should do. When that's sorted out correctly, it should compile ok, and your rBtnAdicChange method should work fine... And another thing, perhaps you could use Halt instead of Application.Terminate. I think the latter makes abnormal program termination... ---------------------------------------------------------------------- fiqs · 2011-03-23 23:23 Quote from: TurboRascal on March 24, 2011, 12:08:51 amWhere did you define TfrmAdic class? In another unit? If so, why did you declare frmAdic in this unit? If that's the problem you should add the unit where frmAdic is declared to the uses statement in the interface section of this unit, if not already done (is it possibly "unit3" there?)... If so, simply removing the frmAdic var declaration should do. When that's sorted out correctly, it should compile ok, and your rBtnAdicChange method should work fine... And another thing, perhaps you could use Halt instead of Application.Terminate. I think the latter makes abnormal program termination... Firstly, thank you for your help. The TfrmAdic is defined in the Unit1(TfrmAdic). Yes, in another unit. The problem is, when I try to add the Unit1 in the uses statment, I get the following error: Code: [Select]unit2.pas(9,18) Fatal: Circular unit reference between Unit2 and Unit1 And when I remove the frmAdic var declaration(from the Unit2, right?) I get the following error: Code: [Select]unit2.pas(57,9) Error: Identifier not found "frmAdic" This without the Unit1 in the uses statment, because with the Unit1, I get the first error. If you want, I can post all the Units here. And about the use of Halt, you mean Application.Halt, just Halt or what? ---------------------------------------------------------------------- TurboRascal · 2011-03-24 00:27 Quote from: fiqs on March 24, 2011, 12:23:41 amThe TfrmAdic is defined in the Unit1(TfrmAdic). Yes, in another unit. The problem is, when I try to add the Unit1 in the uses statment, I get the following error: Code: [Select]unit2.pas(9,18) Fatal: Circular unit reference between Unit2 and Unit1 And when I remove the frmAdic var declaration(from the Unit2, right?) I get the following error: Code: [Select]unit2.pas(57,9) Error: Identifier not found "frmAdic" This without the Unit1 in the uses statment, because with the Unit1, I get the first error. If you want, I can post all the Units here. And about the use of Halt, you mean Application.Halt, just Halt or what? The "circular reference" is obviously a consequence of you using unit2 in unit1, so this happens when you also use unit1 in unit2. However, you must use unit1 in unit2 or you cannot call frmAdic. You can avoid the circular dependency problem if you use those units from implementation instead of interface section. That works only if you don't have declarations in the used unit that the other unit needs, but I guess you don't. So, add "uses unit1;" under the implementation keyword and see if it works ok. BTW I think it's wise to always use own units within implementation whenever you don't need their declarations. That way you avoid circular reference problems in advance. And I mean just "Halt", not "Application.Halt". It' s a procedure specifically meant for this use, to be called like that. You may also use Halt(number) if you want the program to return a value IIRC... ---------------------------------------------------------------------- typo · 2011-03-24 01:45 sl.Free frees the newly created sl. ---------------------------------------------------------------------- fiqs · 2011-03-24 16:49 Quote from: TurboRascal on March 24, 2011, 01:27:26 amQuote from: fiqs on March 24, 2011, 12:23:41 amThe TfrmAdic is defined in the Unit1(TfrmAdic). Yes, in another unit. The problem is, when I try to add the Unit1 in the uses statment, I get the following error: Code: [Select]unit2.pas(9,18) Fatal: Circular unit reference between Unit2 and Unit1 And when I remove the frmAdic var declaration(from the Unit2, right?) I get the following error: Code: [Select]unit2.pas(57,9) Error: Identifier not found "frmAdic" This without the Unit1 in the uses statment, because with the Unit1, I get the first error. If you want, I can post all the Units here. And about the use of Halt, you mean Application.Halt, just Halt or what? The "circular reference" is obviously a consequence of you using unit2 in unit1, so this happens when you also use unit1 in unit2. However, you must use unit1 in unit2 or you cannot call frmAdic. You can avoid the circular dependency problem if you use those units from implementation instead of interface section. That works only if you don't have declarations in the used unit that the other unit needs, but I guess you don't. So, add "uses unit1;" under the implementation keyword and see if it works ok. BTW I think it's wise to always use own units within implementation whenever you don't need their declarations. That way you avoid circular reference problems in advance. And I mean just "Halt", not "Application.Halt". It' s a procedure specifically meant for this use, to be called like that. You may also use Halt(number) if you want the program to return a value IIRC... Finally, it worked! Thank you. Another question, what do you think about this radiobutton method using Form.Show? Do you know any better methods? And again, thanks! ---------------------------------------------------------------------- typo · 2011-03-24 17:01 QuoteAnother question, what do you think about this radiobutton method using Form.Show? Do you know any better methods? I didn't quite understand how you did it. You may need to BringToFront the form that you showed up last. ---------------------------------------------------------------------- TurboRascal · 2011-03-24 19:01 I think that way you used to hide and show forms should be right, if it works ok for you...