Quesiton for Radler


I want to put all values in listview into file and with checkbox in it, and when i load the file i want all values go into listview with the checkboxes

Alright!!!
palli011000Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

LischkeCommented:
Palli, you should carefully test the code given by Radler. It is not as general as he said it would be. Try it out. If the listview contains 0 items an exception is raised and if there are more than 32 items the provided space is not enough to hold all check values.

Ciao, Mike
0
palli011000Author Commented:
What!!! Radler

can you change this?
0
nricoCommented:
You should make an array that holds all the checked/unchecked values. Or you store a series of records like this:

Record
  Name:String;
  Checked:Boolean;
End;
0
Build an E-Commerce Site with Angular 5

Learn how to build an E-Commerce site with Angular 5, a JavaScript framework used by developers to build web, desktop, and mobile applications.

palli011000Author Commented:
Radler?
0
palli011000Author Commented:
Radler?
0
RadlerCommented:
Hi I'm here.
All assertions are true.
The limit is 32 items and the 0 condition is not checked.
Thanks to all to remind me :-)
To correct the code to save the of "ilimited" items I'll take more code lines. I'm doing it now. wait ten minutes.
Ah, When( event or moment ) you desire load the ListView ?

T++, Radler.
0
RadlerCommented:
I'm back again.
The new code to comport all situations simple yet.

procedure TForm1.SaveBtnClick(Sender: TObject);
var
      Stream : TMemoryStream;
      i : DWORD;
      State : array of byte;
begin
      Stream:=TMemoryStream.Create;
      Stream.WriteComponent( Self.ListView1 );
      SetLength( State , ListView1.Items.Count );
      if ListView1.Items.Count > 0 then begin
            for i:=0 to ListView1.Items.Count-1 do begin
                  if ListView1.Items.Item[i].Checked then begin
                        State[i]:=1;
                        //Inc( State, 1 shl i );
                  end else begin
                        State[i]:=0;
                  end;
            end;
            Stream.WriteBuffer( State[0], High( State )+1);
      end;
      Stream.SaveToFile( 'c:\comp.txt');
      Stream.Free;
end;


procedure TForm1.LoadBtnClick(Sender: TObject);
var
      Stream : TMemoryStream;
      i : integer;
      State : array of byte;
begin
      ListView1.Items.Clear;
      Stream:=TMemoryStream.Create;
      Stream.LoadFromFile( 'c:\comp.txt' );
      Stream.ReadComponent( ListView1 );
      SetLength( State, ListView1.Items.Count );
      i:=Length( State );
      Stream.Seek( -i, soFromEnd );
      Stream.ReadBuffer( State[0], i);
      Stream.Free;
      if ListView1.Items.Count > 0 then begin
            for i:=0 to ListView1.Items.Count-1 do begin
                  if (State[i]<>0) then begin
                        ListView1.Items.Item[i].Checked:=True;
                  end else begin
                        ListView1.Items.Item[i].Checked:=False;
                  end;
            end;
      end;
end;


You is in debt about where to put this palli.
I'm waiting for your notification.

T++, Radler.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
palli011000Author Commented:
Still need function
0
RadlerCommented:
Thanks Palli.
On demand ....

T++, Radler.
0
palli011000Author Commented:
one thing, if i have listview on form2 ( unit2 ) and try to load old file into listview that are on form2 from form1 , the checkbox will not come , that where checked or not checked

palli
0
RadlerCommented:
Send your code to roger@ars.com.br to more effective analisys.

T++, Radler.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Delphi

From novice to tech pro — start learning today.