Показать сообщение отдельно
  #8  
Старый 16.10.2023, 10:55
leon2009 leon2009 вне форума
Новичок
 
Регистрация: 18.03.2009
Сообщения: 71
Репутация: 10
Стрелка понял как объяснить

когда все значение заполнены , то все хорошо!
но когда значение вытаскиваются = здесь ругается т.е.
ругается:
Код:
procedure TForm1.Button2Click(Sender: TObject);
var  obj : TFileItemData;
begin
obj := ListBox1.Items.Objects[2] As TFileItemData;
supertest(obj.Value1,obj.Value2, obj.Value3, obj.Value4, obj.Value5);
end;
Работает:
Код:
procedure TForm1.Button2Click(Sender: TObject);
begin
supertest('1111','2222',333,444,555);
end;

и весь код:

Код:
unit Unit1;

interface

uses
  Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
  Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls;

type
  TForm1 = class(TForm)
    ListBox1: TListBox;
    ListBox2: TListBox;
    Button1: TButton;
    Button2: TButton;
    procedure Button1Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);

 type
  TInsertImageToDbCallBack = procedure(AFileName,Atrib: String; ASize1, Aid, Arews: Integer) of object;

  private
    { Private declarations }
  public
  procedure FileImg(const dirName:string; ACallBack : TInsertImageToDbCallBack);
  procedure AddToMemoCb(AFileName,Atrib: String; ASize,Aid,Arews: Integer);
  procedure supertest(FileName2,trib2: String; id2,Size2,rews2: Integer);
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

type
  TFileItemData = class
    Value1 : String;
    Value2 : String;
    Value3 : Integer;
    Value4 : Integer;
    Value5 : Integer;
    function toString : String;
  end;

function TFileItemData.toString : String;
begin
  Result := Format('Value1: %s; Value2: %s; Value3: %d; Value4: %d; Value5: %d',[Value1,Value2,Value3,Value4,Value5]);
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
FileImg('G:\leon\delphis\delphi64\sql2\06\Win32\Debug\db\',AddToMemoCb);
end;

procedure TForm1.supertest(FileName2,trib2:String; id2,Size2,rews2:Integer);
var  obj : TFileItemData;
    begin
      obj := TFileItemData.Create;
      obj.Value1 := FileName2;
      obj.Value2 := trib2;
      obj.Value3 := id2;
      obj.Value4 := Size2;
      obj.Value5 := rews2;
      ListBox2.Items.AddObject(obj.toString,obj);
 // listbox2.Items.Add(Format('id: %d; File: %s; Size: %d',[id2,FileName2,Size2,rews2,trib2]));
end;

procedure TForm1.Button2Click(Sender: TObject);
var  obj : TFileItemData;
begin
//obj := ListBox1.Items.Objects[ListBox1.ItemIndex] As TFileItemData;
obj := ListBox1.Items.Objects[2] As TFileItemData;
supertest(obj.Value1,obj.Value2, obj.Value3, obj.Value4, obj.Value5);
//supertest('1111','2222',333,444,555);
end;

procedure TForm1.FileImg(const dirName:string; ACallBack : TInsertImageToDbCallBack);
var
  searchResult: TSearchRec; x,x1:integer;  st:string;
begin
x:=0; x1:=1; st:='111';
  if FindFirst(dirName+'\*', faAnyFile, searchResult)=0 then begin
    try
      repeat
        if (searchResult.Attr and faDirectory)=0 then begin
          if SameText(ExtractFileExt(searchResult.Name), '.jpg') then begin
          inc(x,1);
            ACallBack(IncludeTrailingBackSlash(dirName)+searchResult.Name,st,searchResult.Size,x,x1);
        end;
        end else if (searchResult.Name<>'.') and (searchResult.Name<>'..') then begin
         FileImg(IncludeTrailingBackSlash(dirName)+searchResult.Name,AddToMemoCb);
         end;
      until FindNext(searchResult)<>0
    finally
      FindClose(searchResult);
    end;
  end;
end;

procedure TForm1.AddToMemoCb(AFileName,Atrib:String; ASize,Aid,Arews:Integer);
begin
listbox1.Items.Add(Format('id: %d; File: %s; Size: %d; Reviews: %d; Attribute: %s',[Aid,AFileName,ASize,Arews,Atrib]));
end;

end.
Ответить с цитированием