Tokay Posted March 14, 2022 Author Share Posted March 14, 2022 Hmm. And how to connect this with buttons and dataset? Quote Link to comment Share on other sites More sharing options...
irigsoft Posted March 14, 2022 Share Posted March 14, 2022 3 minutes ago, Tokay said: Hmm. And how to connect this with buttons and dataset? if (TuniDBGrid (SelDBGrid).DataSource.DataSet.FindField (FIELDName) <> nil) then begin if TuniDBGrid (SelDBGrid).DataSource.DataSet.FieldByName (FIELDName).IsBlob then begin try uniMainModule.msBinImgStream := TMemoryStream.Create; (LoadFromBlobField(TuniDBGrid (SelDBGrid).DataSource.DataSet.FieldByName (FIELDName), uniMainModule.msBinImgStream)); TUniImage (MyObject).Picture.Bitmap.Canvas.Lock; TUniImage (MyObject).Picture.Bitmap := nil; if uniMainModule.msBinImgStream.Size > 0 then begin TUniImage (MyObject).Picture.Bitmap.LoadFromStream(uniMainModule.msBinImgStream); uniMainModule.msBinImgStream.Free; end; except on E:Exception do begin end; end; TUniImage (MyObject).Picture.Bitmap.Canvas.UnLock; TUniImage (MyObject).Invalidate; TUniImage (MyObject).JSInterface.JSCall('updateLayout', []); end;//If IsBlob end;//If FindField <> nil 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; Quote Link to comment Share on other sites More sharing options...
irigsoft Posted March 14, 2022 Share Posted March 14, 2022 I don't know Your logic, but there are 2 types I've used: 1 Variant: 1. Load Query and get results, before show on Client. 2. Check in DBGrid for every row what is value on one column (like example : active=True/False) 3. If Active=True then load Image from NativeImageLIst Index = 1 4. Draw image on ActionButton 5. Show Result on Client 2 Variant 1. Load Query and get results, before show on Client. 2. Check in DBGrid for every row what is value on one column (like example : active=True/False) 3. If Active=True then draw Image from NativeImageLIst Index = 1 in DBGrid ActionColumn as Blob 4. Load Blob image and draw on ActionButton 5. Show Result on Client My code is not complete, but there are functions how to draw on Component. I create Actionbuttons before show result on Client, every button have name and it's easy for me to find it, so when I know what Image I must draw, then find button and redraw Image from NativeImageList. I have My settings for this Grid and all Action Buttons. First: Check If assigned ImageList on Grid and create it if not exist: if SelDBGrid.Images <> nil then begin ImagesExist := True; If FindComponentEx (SelDBGrid.Images.Name) <> nil then begin GridImageList := TuniImageLIst (SelDBGrid.Images); TuniImageLIst (SelDBGrid.Images).Clear; TuniImageLIst (SelDBGrid.Images).Height := 32; TuniImageLIst (SelDBGrid.Images).Width := 32; end; end; Second: TRY GridImageList := TuniImageList (FindComponentEx ('ImageList_'+ SelDBGrid.Name)); if (not Assigned (GridImageList)) Or (GridImageList = nil) then begin GridImageList := TuniImageList.Create (UniSession.FormsList [UniSession.FormsList.Count -1]);//uniMainModule); GridImageList.Name := 'ImageList_'+ SelDBGrid.Name; GridImageList.UseGlobalCache := True; end; GridImageList.Clear; GridImageList.Height := 32; GridImageList.Width := 32; SelDBGrid.Images := GridImageList; EXCEPT on E:Exception do begin end; END; Third: Find Buttons and draw Image from list. ActionColumnList : TStringList ( i load list with used ActionButtons - I have manual setting for every Grid) for I := ActionColumnList.Count - 1 downto 0 do begin sBtn := TuniBitBtn (FindComponent (ActionColumnList [I])); //search action button by name if Assigned (sBtn) then begin SelDBGrid.Columns.Insert (0);//TColumn.Create(SelDBGrid.Columns); SelDBGrid.Columns [0].Title.Alignment := taCenter; SelDBGrid.Columns [0].Title.Caption := ''; SelDBGrid.Columns [0].Width := iActionColumnWidth; SelDBGrid.Columns [0].Alignment := taCenter; SelDBGrid.Columns [0].ActionColumn.Create; SelDBGrid.Columns [0].ActionColumn.Enabled := True; Try BtnCol := TuniCustomButtonItem (SelDBGrid.Columns [0].ActionColumn.Buttons.Add); SelDBGrid.Columns [0].Title.Caption := TuniControl (sBtn).Caption; BtnCol.UI := 'ActionBtn_' + ActionColumnList [I]; BtnCol.Hint := sBtn.Hint; BtnCol.Caption := sBtn.Caption; SelDBGrid.Columns [0].ActionColumn.Buttons[BtnCol.ButtonId].Width := iActionColumnWidth; if Assigned (TuniBitBtn (sBtn).Glyph) then begin try msBinImgStream := TMemoryStream.Create; Bmp := TBitMap.Create; TuniBitBtn (sBtn).Glyph.SaveToStream (msBinImgStream); Bmp.Canvas.Lock; msBinImgStream.Position := 0; if msBinImgStream.Size > 0 then begin Bmp.LoadFromStream(msBinImgStream); Bmp := ResizeBmp(Bmp,GridImageList.Height,GridImageList.Width); //My internal function to draw image on canvas with size) BtnCol.ImageIndex := GridImageList.Add (Bmp,nil); end; msBinImgStream.Size := 0; msBinImgStream.Free; Bmp.Free; except on E:Exception do begin end; end; Bmp.Canvas.UnLock; BtnCol := nil; end;//IF Assigend except End; end;//If end;//for end;//if (ActionColumnList.Count > 0) ActionColumnList.Clear; ActionColumnList.Free; end; Now, I open query and Show Result. Quote Link to comment Share on other sites More sharing options...
irigsoft Posted March 14, 2022 Share Posted March 14, 2022 @Tokay, last code and explanation will help to get Your mission. Quote Link to comment Share on other sites More sharing options...
Tokay Posted March 14, 2022 Author Share Posted March 14, 2022 Ok, thank you very much! I'll analyze your and Sherzod solutions. Quote Link to comment Share on other sites More sharing options...
Tokay Posted March 21, 2022 Author Share Posted March 21, 2022 It seems that Sherzod's variant works. But I've implemented other solution: changed numbers to PNG image links + OnClick Events + Hints. All works fine, thank you for support. 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.