Solved

Need Help Delphi 2010 CheckBox1 Stored value in memo

Posted on 2016-11-28
13
11 Views
Last Modified: 2016-11-28
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 36

Expert Comment

by:Geert Gruwez
Comment Utility
checkbox.text doesn't exist ?

it's certainly not the constructor
0
 
LVL 36

Expert Comment

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

Author Comment

by:Yaku Kakashi
Comment Utility
Sorry that is CheckBox1.Checked
0
 

Author Comment

by:Yaku Kakashi
Comment Utility
Just don't mind the other types I remove some of those Just the button1 only
0
 
LVL 36

Assisted Solution

by:Geert Gruwez
Geert Gruwez earned 500 total points
Comment Utility
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
Comment Utility
Geert Gruwez I'll give it a try. Thank You.
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 

Author Comment

by:Yaku Kakashi
Comment Utility
it Works Geert Gruwez, thank you.
0
 

Author Comment

by:Yaku Kakashi
Comment Utility
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 36

Accepted Solution

by:
Geert Gruwez earned 500 total points
Comment Utility
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
Comment Utility
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
Comment Utility
Thank You Geert Gruwez, You are a life saver thank you so much.
0
 

Author Closing Comment

by:Yaku Kakashi
Comment Utility
Question answered by: Geert Gruwez
Thanks Dude
0
 
LVL 36

Expert Comment

by:Geert Gruwez
Comment Utility
no problem, dude
1

Featured Post

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

771 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

Need Help in Real-Time?

Connect with top rated Experts

7 Experts available now in Live!

Get 1:1 Help Now