Solved

Need Help Delphi 2010 CheckBox1 Stored value in memo

Posted on 2016-11-28
13
56 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
 

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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
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…
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…

911 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

18 Experts available now in Live!

Get 1:1 Help Now