Solved

Need Help Delphi 2010 CheckBox1 Stored value in memo

Posted on 2016-11-28
13
66 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
NAS Cloud Backup Strategies

This article explains backup scenarios when using network storage. We review the so-called “3-2-1 strategy” and summarize the methods you can use to send NAS data to the cloud

 

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

ScreenConnect 6.0 Free Trial

Check out the updates in one game-changing release, ScreenConnect 6.0, based on partner feedback. New features include a redesigned UI that improves session organization and overall user experience. See the enhancements for yourself!

Question has a verified solution.

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

Suggested Solutions

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

773 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