Solved

Need Help Delphi 2010 CheckBox1 Stored value in memo

Posted on 2016-11-28
13
71 Views
Last Modified: 2016-12-10
Hello Guys I'm new with Delphi which uses pascal language.
I'm trying to create simple application which loaded all values in sMemo.Text. All Strings were working fine except with Boolean values "CheckBox and radio Buttons"
here is the line I'm using
sMemo1.Lines.Add(sCheckBox1.Create );
it gives me an error
[DCC Error] Unit1.pas(44): E2035 Not enough actual parameters.

here is my whole code

unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, sCheckBox, sRadioButton, sGroupBox, sButton, sEdit, sMemo,
  sLabel;

type
  TForm1 = class(TForm)
    sMemo1: TsMemo;
    sEdit1: TsEdit;
    sEdit2: TsEdit;
    sEdit3: TsEdit;
    sButton1: TsButton;
    sButton2: TsButton;
    sGroupBox1: TsGroupBox;
    sRadioButton1: TsRadioButton;
    sRadioButton2: TsRadioButton;
    sCheckBox1: TsCheckBox;
    sMemo2: TsMemo;
    sLabel1: TsLabel;
    procedure sButton1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.sButton1Click(Sender: TObject);
begin
sMemo1.Clear;
sMemo1.Lines.Add(sEdit1.Text);
sMemo1.Lines.Add(sEdit2.Text);
sMemo1.Lines.Add(sEdit3.Text);
sMemo1.Lines.Add(sCheckBox1.Create);
end;
end.


Anyone here knows that. My main purpose with this app is to load all configuration into memo instead of an ini file wich is easy to read an modified with someone. I want to load all config i memo and encrypt  content in memo and save it as a file format
0
Comment
Question by:Yaku Kakashi
  • 8
  • 5
13 Comments
 
LVL 37

Expert Comment

by:Geert Gruwez
ID: 41903736
checkbox.text doesn't exist ?

it's certainly not the constructor
0
 
LVL 37

Expert Comment

by:Geert Gruwez
ID: 41903737
what components are those ?
never seen an sRadioButton, sGroupBox, etc in the uses clause
0
 

Author Comment

by:Yaku Kakashi
ID: 41903749
Sorry that is CheckBox1.Checked
0
Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 

Author Comment

by:Yaku Kakashi
ID: 41903751
Just don't mind the other types I remove some of those Just the button1 only
0
 
LVL 37

Assisted Solution

by:Geert Gruwez
Geert Gruwez earned 500 total points
ID: 41903752
for the checkbox and radiobutton you'll have to convert a boolean to a string


why exactly do you want to use "a visual component" (= memo) for something you don't want users to see ?
it is a common misconcept
use a TStrings instead

procedure TForm1.sButton1Click(Sender: TObject);
  function BoolToStr(b: Boolean): string;
  begin
    Result := '0';
    if b then Result := '1';
  end;
var List: TStrings;
begin
  List := TStringList.Create;
  try
    List.Add(sEdit1.Text);
    List.Add(sEdit2.Text);
    List.Add(sEdit3.Text);
    List.Add(BoolToStr(sCheckBox1.Checked));
    List.SaveToFile('yourtextfile.txt');
    // to see the actual text in a memo: 
    // smemo1.Lines.Assign(List);
  finally
    List.Free;
  end;
end.

Open in new window

1
 

Author Comment

by:Yaku Kakashi
ID: 41903766
Geert Gruwez I'll give it a try. Thank You.
0
 

Author Comment

by:Yaku Kakashi
ID: 41903788
it Works Geert Gruwez, thank you.
0
 

Author Comment

by:Yaku Kakashi
ID: 41903816
Hello sorry to ask you again. how can I retrieve in back using button2
here is My code

function StrToBool(b: Boolean): string;
  begin
    Result := '0';
    if b then Result := '1';
  end;
var List: TStrings;
begin
sEdit1.Text := sMemo1.Lines[0];
sEdit1.Text := sMemo1.Lines[1];
sEdit1.Text := sMemo1.Lines[2];
sCheckBox1.Checked := sMemo1.Lines[3];
end;
0
 
LVL 37

Accepted Solution

by:
Geert Gruwez earned 500 total points
ID: 41903950
i thought you were going to come back ...
there will be a problem when you add components.


procedure TForm1.sButton1Click(Sender: TObject);
begin
  SaveSettings;
end;

procedure TForm1.SaveSettings;
  function BoolToStr(b: Boolean): string;
  begin
    Result := '0';
    if b then Result := '1';
  end;
var List: TStrings;
begin
  List := TStringList.Create;
  try
    List.Values['Edit1'] := sEdit1.Text;
    List.Values['Edit2'] := sEdit2.Text;
    List.Values['Edit3'] := sEdit3.Text;
    List.Values['Check1'] := BoolToStr(sCheckBox1.Checked);
    List.SaveToFile('yourtextfile.txt');
    // to see the actual text in a memo: 
    // smemo1.Lines.Assign(List);
  finally
    List.Free;
  end;
end.

procedure TForm1.LoadSettings;
function StrToBool(s: string): boolean;
  begin
    Result := False;
    if s = '1' then Result := True;
  end;
var List: TStrings;
begin
  List := TStringList.Create;
  try
    List.LoadFromFile('yourtextfile.txt');
    sEdit1.Text := List.Values['Edit1'];
    sEdit2.Text := List.Values['Edit2'];
    sEdit3.Text := List.Values['Edit3'];
    sCheckBox1.Checked := StrToBool(List.Values['Check1']);
  finally
    List.Free;
  end;
end;

Open in new window


Hit Ctrl-Shift-C for code completion after replacing the Button1Click procedure with above code
0
 

Author Comment

by:Yaku Kakashi
ID: 41903994
I already Solve it using this code..

procedure TForm1.sButton2Click(Sender: TObject);
var
  value :  String ;
begin
value := sMemo1.Lines[0];
sCheckBox1.Checked := StrToBool(value);
end;

end.
0
 

Author Comment

by:Yaku Kakashi
ID: 41903998
Thank You Geert Gruwez, You are a life saver thank you so much.
0
 

Author Closing Comment

by:Yaku Kakashi
ID: 41904005
Question answered by: Geert Gruwez
Thanks Dude
0
 
LVL 37

Expert Comment

by:Geert Gruwez
ID: 41904087
no problem, dude
1

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …

829 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question