Gauravg Posted November 6, 2020 Share Posted November 6, 2020 I need to show image seperately when user selects an item from grid. Image element is outside grid. I do not want to use TUniDBImage since it will be connected to datasource and will select first image by default. Quote Link to comment Share on other sites More sharing options...
Sherzod Posted November 6, 2020 Share Posted November 6, 2020 22 minutes ago, Gauravg said: I need to show image seperately when user selects an item from grid. Image element is outside grid. Hello, procedure TMainForm.UniDBGrid1SelectionChange(Sender: TObject); begin end; UniDBGrid.OnSelectionChange ? Quote Link to comment Share on other sites More sharing options...
Gauravg Posted November 6, 2020 Author Share Posted November 6, 2020 2 minutes ago, Sherzod said: Hello, procedure TMainForm.UniDBGrid1SelectionChange(Sender: TObject); begin end; UniDBGrid.OnSelectionChange ? Hello Sherzod, I know it has to be done either on cellclicked or selectionchange of grid. To add image normally to an image control we specify UniImage.Picture.LoadFromFile(FolderPath+'images\'+IntToStr(adr)+'.jpg'). I want to display image which is in variant variable. I want to know which prooerty of image control i need to use to set image from variant type. Quote Link to comment Share on other sites More sharing options...
Sherzod Posted November 6, 2020 Share Posted November 6, 2020 14 minutes ago, Gauravg said: I want to display image which is in variant variable. I want to know which prooerty of image control i need to use to set image from variant type. Hello, Please clarify, I do not understand your case. Quote Link to comment Share on other sites More sharing options...
Gauravg Posted November 6, 2020 Author Share Posted November 6, 2020 Just now, Sherzod said: Hello, Please clarify, I do not understand your case. Hello, My image is in variant type variable. How to display in image control? Quote Link to comment Share on other sites More sharing options...
Sherzod Posted November 6, 2020 Share Posted November 6, 2020 5 minutes ago, Gauravg said: My image is in variant type variable. Simple testcase? Quote Link to comment Share on other sites More sharing options...
irigsoft Posted November 6, 2020 Share Posted November 6, 2020 10 minutes ago, Gauravg said: Hello, My image is in variant type variable. How to display in image control? What kind of variable (jpeg, bmp, png) or other image files formats ? Quote Link to comment Share on other sites More sharing options...
irigsoft Posted November 6, 2020 Share Posted November 6, 2020 "UniImage.Picture.LoadFromFile(FolderPath+'images\'+IntToStr(adr)+'.jpg')." I think Your code is useless if you use jpeg or png formats, You better draw in uniImage control Bitmap from file Quote Link to comment Share on other sites More sharing options...
Gauravg Posted November 6, 2020 Author Share Posted November 6, 2020 5 minutes ago, irigsoft said: What kind of variable (jpeg, bmp, png) or other image files formats ? Hello, oImage: variant; oImage:=DSetObject.FieldByName('Pic').AsVariant; UniImage1.Picture := oImage;//which property of control need to be used to set image Thank you Quote Link to comment Share on other sites More sharing options...
irigsoft Posted November 6, 2020 Share Posted November 6, 2020 Just now, Gauravg said: Hello, oImage: variant; oImage:=DSetObject.FieldByName('Pic').AsVariant; UniImage1.Picture := oImage;//which property of control need to be used to set image Thank you I use it by this way to show/draw image in grid: 1. I save images in database, and show it in uniDBGrid when draw Grid if (Sender As TDBGrid).DataSource.DataSet.RecNo >= 0 then begin (SENDER AS TDBGrid).Canvas.FillRect(Rect); R := Rect; R.Right := R.Left + Trunc((R.Right - R.Left) ); if (Column.Field is TBlobField) AND (Column.Width > 0) then begin TRY bmpImage := tBitmap.Create; bmpStream := TMemoryStream.Create; //load from datasource //LoadFromBlobField (Column.Field,bmpStream); //load from file bmpStream.loadFromFile ('Youpath'); bmpStream.Position := 0; bmpImage.LoadFromStream (bmpStream); bmpImage.Assign(ResizeBmp (bmpImage,Column.Width,Column.Width)); IF THackDBGrid(Sender).DefaultRowHeight <> Column.Width then THackDBGrid(Sender).DefaultRowHeight := Column.Width; THackDBGrid (Sender).RowHeights [0] := THackDBGrid (Sender).Canvas.TextHeight('Wg') + 4; (Sender As TDBGrid).Canvas.StretchDraw (R, bmpImage); (SENDER AS TDBGrid).Canvas.Brush.Style := bsClear; FINALLY bmpStream.Free; bmpImage.Free; END; end; end; You can use this to draw bitmap object of uniImage.Picture.Bitmap Quote Link to comment Share on other sites More sharing options...
irigsoft Posted November 6, 2020 Share Posted November 6, 2020 function LoadFromBlobField(const AField: TField; const Stream: TStream): boolean; var ResultStr: string; PResultStr: PChar; begin Result := false; if (Assigned(AField)) and (Assigned(Stream)) then begin try ResultStr := AField.Value; PResultStr := PChar(ResultStr); Stream.Write(PResultStr^, Length(ResultStr)); Stream.Seek(0,0); Result := true; except end; end; end; I think AField can be a variant type or just be used to apply the value of the field to the image Quote Link to comment Share on other sites More sharing options...
irigsoft Posted November 6, 2020 Share Posted November 6, 2020 Result: Quote Link to comment Share on other sites More sharing options...
Gauravg Posted November 6, 2020 Author Share Posted November 6, 2020 36 minutes ago, irigsoft said: Result: Thank you Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.