界面大致如下:            表:list
----------------------    ID  游戏名称  路径         
|1  2  3  4  5  6  7 |    1   传奇      c:\mir2\mir2.exe
|.....               |    2   奇迹      c:\mu\mu2.exe
|29 30 31 32         |    .    .        .
----------------------    .    .        .图片存在SQL数据库里,表名list,下面代码能将SQL里的图片分别读取到1,2,3....中!
1,2,3...都是image控件,要求双击image后能执行相应的游戏路径!
从数据库读取图片和图片双击事件代码都在下面,但不知道怎么结合起来,希望各位大哥能给点意见!以下是从数据库里读图片的代码:
procedure TForm1.loading;
var
  i:integer;
  strm:tadoblobstream;
  jpegimage:tjpegimage;
begin
  for i:=1 to 32 do
  begin
    (FindComponent('label'+inttostr(i)) as Tlabel).Caption := '';
    (FindComponent('image'+inttostr(i)) as Timage).Picture.Graphic := nil;
  end;
  for  i:=1 to ADOQuery1.RecordCount do
  begin
     if i>32 then
     begin
     exit;
     end;
    try
      strm := tadoblobstream.Create(TBlobField(ADOQuery1.FieldByName('图标')),bmread); //从SQL中读取图标,赋值到变量strm
      (FindComponent('label'+inttostr(i)) as Tlabel).Caption := ADOQuery1.FieldByName('游戏名称').AsString;
      if adoquery1.fieldbyname('isbmp').asstring ='0' then //判断图像类型
      begin
        jpegimage := tjpegimage.Create;
        try
          jpegimage.LoadFromStream(strm);//从当前位置读入Stream里的数据
          (FindComponent('image'+inttostr(i)) as Timage).Picture.Graphic := jpegimage;
          //(FindComponent('image'+inttostr(i)) as Timage).Picture.Graphic := ADOQuery1.FieldByName('图标');
        finally
          jpegimage.Free;
        end;
      end;
      ADOQuery1.Next;
    finally
      strm.Free ;
    end;
  end;
end;以下是图片双击事件的代码:
procedure TForm1.Image1DblClick(Sender: TObject);
var
  F:TShFileOpStruct;
begin
  if FileExists('c:\boord\boord.txt')//本地游戏路径
  then ShellExecute(handle,'','c:\boord\boord.txt','',nil,SW_Show)//本地机上有游戏,执行游戏
  else begin
    if MessageBox(Handle,'程序将从服务器拷贝该游戏到本地机,确定要复制吗?','提示',MB_OKCANCEL+MB_IconInformation+MB_SystemModal)=IDOK then
    begin
    F.wnd:=Handle;
    F.wFunc:=FO_COPY;
    F.pFrom:='E:\boord';//服务器上该游戏的文件夹的路径
    F.pTo:='c:\';//拷贝到本地上的路径
    F.fFlags:=FOF_FilesOnly;
    if ShFileOperation(F)<>0
    then MessageBox(Handle,'文件拷贝失败!请再试一次,或和管理员联系!','提示',MB_OK+MB_IconInformation)
    else
      MessageBox(Handle,'文件拷贝成功!','提示',MB_OK+MB_IconInformation);
      ShellExecute(handle,'','c:\boord\boord.txt','',nil,SW_Show);//拷贝完毕,执行游戏
    end;
  end;
end;

解决方案 »

  1.   

    for i:=1 to RecordCount do
      begin
        (FindComponent('label'+inttostr(i)) as Tlabel).Caption := '';
        (FindComponent('image'+inttostr(i)) as Timage).Picture.Graphic := GetPic(i);//自己写代码存了
        (FindComponent('image'+inttostr(i)) as Timage). tag := I;
        (FindComponent('image'+inttostr(i)) as Timage).OnClick := RunGame;
      end;procedure RunGame(Sender:TObject);begin
      ADOQuery1.RecNo := Timage(Sender).Tag - 1;
      ShellExecute(handle,'',ADOQuery1.FieldByName('GameFilePath').AsString,'',nil,SW_Show);
    end;大概就这样了,你自己理解一下。
      

  2.   

    (FindComponent('image'+inttostr(i)) as Timage).OnClick := RunGame;这个应该是单击事件吧,要双击后执行程序应该怎么弄呢?
      

  3.   

    直接写  OnDblClick,如:
    (FindComponent('image'+inttostr(i)) as Timage).OnDblClick := RunGame;会编译出错的!