-1

コードに問題がありますが、解決策が見つかりません。すでにさまざまな方法で変更されていますが、成功していません。

コード:

private
{ Private declarations }
procedure getImgInfo(Sender: TObject; A, B: String);

と:

procedure TfMain.Button1Click(Sender: TObject);
var
i, Idx, Left, Top, Count : integer;
Graph : TGraphic;
Img : TImage;
EdPath, EdFileName : TEdit;
begin
  openImg.Execute;
  Left := 5;
  Top := 5;
  Count := 0;
  Idx := 0;
for i:=0 to openImg.Files.Count-1 do
  begin
    try
      begin
        Graph := TPngImage.Create;
        Graph.LoadFromFile(openImg.Files[i]);

        EdPath := TEdit.Create(pImgs);
        EdPath.Left := Left + 101;
        EdPath.Visible := False;
        EdPath.Text := ExtractFilePath(openImg.Files[i]);

        EdFileName := TEdit.Create(pImgs);
        EdFileName.Left := Left + 101;
        EdFileName.Visible := False;
        EdFileName.Text := ExtractFileName(openImg.Files[i]);

        Img := TImage.Create(pImgs);
        Img.Parent := pImgs;
        Idx := Idx + 1;
        Img.Name := 'Img_'+IntToStr(Idx);
        Img.Width := 100;
        Img.Height := 100;
        Img.Left := Left;
        Img.Proportional := True;
        Left := Left + 101;
        Img.Top := Top;
        Img.Picture.Assign(Graph);
        Img.BringToFront;
        Count := Count + 1;
        Img.OnClick := getImgInfo(Img, edPath.Text, edFileName.Text); //Error line

        if Count = 2 then
          begin
            Left := 5;
            Top := Top + 101;
            Count := 0;
          end;
      end;
    except on E : Exception do
      ShowMessage('Error: :' + E.Message);
    end;
  end;
end;

エラー:

[dcc32 エラー] uMain.pas(74): E2010 互換性のない型: 'TNotifyEvent' および 'procedure, untyped pointer or untyped parameter'

なにが問題ですか?ありがとう!

4

2 に答える 2

0

代わりに、次のようなことを試してください。

type
  PImageInfo = ^ImageInfo;
  ImageInfo = record
    Path: String;
    FileName: String;
    Img: TImage;
    EdPath: TEdit;
    EdFileName : TEdit;
    // anything else you need...
  end;

private
  { Private declarations }
  Images: array of ImageInfo;
  procedure ImageClicked(Sender: TObject);

procedure TfMain.Button1Click(Sender: TObject);
var
  i, ImgLeft, ImgTop, Count : integer;
  Graph : TGraphic;
  Info: PImageInfo;
begin
  if not openImg.Execute then Exit;

  ImgLeft := 5;
  ImgTop := 5;

  Count := Length(Images);
  try
    SetLength(Images, Count + openImg.Files.Count);

    for I := 0 to openImg.Files.Count-1 do
    begin
      Graph := TPngImage.Create;
      try
        Graph.LoadFromFile(openImg.Files[i]);

        Info := @Images[Count];

        Info.Path := ExtractFilePath(openImg.Files[i]);
        Info.FileName := ExtractFileName(openImg.Files[i]);
        Info.Img := nil;
        Info.EdPath := nil;
        Info.EdFileName := nil;

        try
          Info.EdPath := TEdit.Create(pImgs);
          Info.EdPath.Left := ImgLeft + 101;
          Info.EdPath.Visible := False;
          Info.EdPath.Text := Path;

          Info.EdFileName := TEdit.Create(pImgs);
          Info.EdFileName.Left := ImgLeft + 101;
          Info.EdFileName.Visible := False;
          Info.EdFileName.Text := Images[Count].FileName;

          Info.Img := TImage.Create(pImgs);
          Info.Img.Parent := pImgs;
          Info.Img.Tag := Count;
          Info.Img.Name := 'Img_'+IntToStr(Count);
          Info.Img.SetBounds(ImgLeft, ImgTop, 100, 100);
          Info.Img.Proportional := True;
          Info.Img.OnClick := ImageClicked;
          Info.Img.Picture.Assign(Graph);
          Info.Img.BringToFront;
        except
          Info.EdPath.Free;
          Info.EdFileName.Free;
          Info.Img.Free;
          raise;
        end;
      finally
        Graph.Free;
      end;

      Inc(Count);
      if (Count mod 2) = 0 then
      begin
        ImgLeft := 5;
        Inc(ImgTop, 101);
      end else
        Inc(ImgLeft, 101);
    end;
  except
    on E : Exception do
    begin
      SetLength(Images, Count);
      ShowMessage('Error: :' + E.Message);
    end;
  end;
end;

procedure TfMain.ImageClicked(Sender: TObject);
var
  Info: PImageInfo;
begin
  Info := @Images[(Sender as TImage).Tag];
  // use Info as needed...
end;
于 2013-08-01T19:38:11.597 に答える