Forum > LCL

[SOLVED] VST Integer

<< < (2/3) > >>

bytebites:

--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---IntToStr(Data^.Wiek)This is not variable.

Pe3s:
FWiek is variable

--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---FWiek := IntToStr(Data^.Wiek);

Handoko:
You should provide the whole source code. Without it, my only guess is:


--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---procedure TForm1.Button1Click(Sender: TObject);var  Stream: TStream;  FWiek: array of Byte;  len: Integer;begin//  Stream := TFileStream.Create('test.txt', fmOpenRead);  Stream.Read(len, SizeOf(len));  SetLength(FWiek, len);  Stream.Read(FWiek, len);  Data^.Wiek := FWiek;//  Stream.Free;end;

Pe3s:
Source code

--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---unit Unit1; {$mode objfpc}{$H+} interface uses  Classes, SysUtils, Forms, Controls, Graphics, Dialogs, ComCtrls, StdCtrls,  Buttons, ExtCtrls, VirtualTrees; type  PData = ^TData;  TData = packed record    Imie, Nazwisko, Miejscowosc: String;    Wiek: Integer;  end;   { TForm1 }   TForm1 = class(TForm)    Button1: TButton;    Button2: TButton;    Button3: TButton;    Button4: TButton;    Edit1: TEdit;    Edit2: TEdit;    Edit3: TEdit;    Edit4: TEdit;    ImageList1: TImageList;    Label1: TLabel;    Label2: TLabel;    Label3: TLabel;    Label4: TLabel;    SpeedButton1: TSpeedButton;    SpeedButton2: TSpeedButton;    VST: TVirtualStringTree;    procedure Button1Click(Sender: TObject);    procedure Button4Click(Sender: TObject);    procedure SpeedButton1Click(Sender: TObject);    procedure SpeedButton2Click(Sender: TObject);    procedure VSTFreeNode(Sender: TBaseVirtualTree; Node: PVirtualNode);    procedure VSTGetNodeDataSize(Sender: TBaseVirtualTree;      var NodeDataSize: Integer);    procedure VSTGetText(Sender: TBaseVirtualTree; Node: PVirtualNode;      Column: TColumnIndex; TextType: TVSTTextType; var CellText: String);    procedure VSTLoadNode(Sender: TBaseVirtualTree; Node: PVirtualNode;      Stream: TStream);    procedure VSTMeasureItem(Sender: TBaseVirtualTree; TargetCanvas: TCanvas;      Node: PVirtualNode; var NodeHeight: Integer);    procedure VSTSaveNode(Sender: TBaseVirtualTree; Node: PVirtualNode;      Stream: TStream);  private   public   end; var  Form1: TForm1; implementation {$R *.lfm} { TForm1 } procedure TForm1.VSTFreeNode(Sender: TBaseVirtualTree; Node: PVirtualNode);var  Data: PData;begin  Data := Sender.GetNodeData(Node);  if Assigned(Data) then begin    Finalize(Data^);  end;end; procedure TForm1.VSTGetNodeDataSize(Sender: TBaseVirtualTree;  var NodeDataSize: Integer);begin  NodeDataSize := SizeOf(TData);end; procedure TForm1.VSTGetText(Sender: TBaseVirtualTree; Node: PVirtualNode;  Column: TColumnIndex; TextType: TVSTTextType; var CellText: String);var  Data: PData;begin  Data := VST.GetNodeData(Node);  case Column of  0: CellText := Data^.Imie;  1: CellText := Data^.Nazwisko;  2: CellText := IntToStr(Data^.Wiek);  3: CellText := Data^.Miejscowosc;  end;end; procedure TForm1.VSTMeasureItem(Sender: TBaseVirtualTree;  TargetCanvas: TCanvas; Node: PVirtualNode; var NodeHeight: Integer);begin  NodeHeight := Round((Screen.PixelsPerInch / 96.0) * 40);end; procedure TForm1.VSTLoadNode(Sender: TBaseVirtualTree; Node: PVirtualNode;  Stream: TStream);var  Data: PData;  len: Integer;  FWiek: String;begin  Data := VST.GetNodeData(Node);   Stream.Read(len, SizeOf(len));  SetLength(Data^.Imie, len);  Stream.Read(PChar(Data^.Imie)^, len);   Stream.Read(len, SizeOf(len));  SetLength(Data^.Nazwisko, len);  Stream.Read(PChar(Data^.Nazwisko)^, len);   Stream.Read(len, SizeOf(len));  FWiek := IntToStr(Data^.Wiek);  SetLength(FWiek, len);  Stream.Read(PChar(IntToStr(Data^.Wiek))^, len);   Stream.Read(len, SizeOf(len));  SetLength(Data^.Miejscowosc, len);  Stream.Read(PChar(Data^.Miejscowosc)^, len);end; procedure TForm1.VSTSaveNode(Sender: TBaseVirtualTree; Node: PVirtualNode;  Stream: TStream);var  Data: PData;  len: Integer;begin  Data := VST.GetNodeData(Node);   len := Length(Data^.Imie);  Stream.Write(len, SizeOf(len));  Stream.Write(PChar(Data^.Imie)^, len);   len := Length(Data^.Nazwisko);  Stream.Write(len, SizeOf(len));  Stream.Write(PChar(Data^.Nazwisko)^, len);   len := Length(IntToStr(Data^.Wiek));  Stream.Write(len, SizeOf(len));  Stream.Write(PChar(IntToStr(Data^.Wiek))^, len);   len := Length(Data^.Miejscowosc);  Stream.Write(len, SizeOf(len));  Stream.Write(PChar(Data^.Miejscowosc)^, len);end; // dodaj daneprocedure TForm1.Button1Click(Sender: TObject);var  Node: PVirtualNode;  Data: PData;begin  VST.NodeDataSize := SizeOf(TData);  Node := VST.AddChild(nil);  Data := VST.GetNodeData(Node);  Data^.Imie := Edit1.Text;  Data^.Nazwisko := Edit2.Text;  Data^.Wiek := StrToInt(Edit3.Text);  Data^.Miejscowosc := Edit4.Text;end; procedure TForm1.Button4Click(Sender: TObject);begin end; procedure TForm1.SpeedButton1Click(Sender: TObject);begin  VST.LoadFromFile(Application.Location + 'dane.txt');end; procedure TForm1.SpeedButton2Click(Sender: TObject);begin  VST.SaveToFile(Application.Location + 'dane.txt');end; end.  

GetMem:
@Pe3s

Too many Stream.Read and Stream.Write. Try something like this(see attachment, VST5):

--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---type   PData = ^TData;   TData = record     FName: String;     FAge: Integer;     //..   end;   procedure TForm1.LoadFromFile(AFile: String);var  FS: TFileStream;  Node: PVirtualNode;  Data: PData;  Cnt, I: Integer;begin  if not FileExists(AFile) then  begin    MessageDlg('File does not exists', mtInformation, [mbOk], 0);    Exit;  end;   VST.BeginUpdate;  try    VST.Clear;    VST.NodeDataSize := SizeOf(TData);     FS := TFileStream.Create(AFile, fmOpenRead or fmShareDenyNone);    try      Cnt := FS.ReadWord;      if Cnt > 0 then      begin        I := 1;        while I <= Cnt do        begin          Node := VST.AddChild(nil);          Data := VST.GetNodeData(Node);          FS.Read(Data^, SizeOf(TData));          Inc(I);        end;      end;    finally      FS.Free;    end;  finally    VST.EndUpdate;  end;end; procedure TForm1.SaveToFile(AFile: String);var  FS: TFileStream;  Node: PVirtualNode;  Data: PData;begin  if VST.RootNodeCount = 0 then  begin    MessageDlg('The list is empty. Nothing to save.', mtInformation, [mbOk], 0);    Exit;  end;   FS := TFileStream.Create(AFile, fmCreate or fmShareDenyWrite);  try    FS.WriteWord(VST.RootNodeCount);    Node := VST.GetFirst;    while Assigned(Node) do    begin      Data := VST.GetNodeData(Node);      FS.Write(Data^, SizeOf(TData));      Node := VST.GetNext(Node);    end;  finally    FS.Free;  end;end; procedure TForm1.bSaveClick(Sender: TObject);begin  if SD.Execute then    SaveToFile(SD.FileName);end; procedure TForm1.bLoadClick(Sender: TObject);begin  if OD.Execute then    LoadFromFile(OD.FileName);end;  

 

Navigation

[0] Message Index

[#] Next page

[*] Previous page

Go to full version