Jump to content

programmerdelphi2k

Members
  • Content Count

    1406
  • Joined

  • Last visited

  • Days Won

    22

Everything posted by programmerdelphi2k

  1. programmerdelphi2k

    Print a jpeg from a table blob field?

    if you can create yourself "Form" with options more used, and define it in your "LPrinter" object, ex: xFrmPrintSetup.ShowModal; ... if xFrmPrintSetup.ModalResult = mrOk then begin LPrinter.BeginDoc; if LPrinter.Printing then // if you use press OK to print!!! begin LPrinter.Title := xFrmPrintSetup.LMyTitle; // from "Printer form result" -> public properties, for example LPrinter.Copies := xFrmPrintSetup.LMyCopyNumber; // ... LPrinter.Canvas.Draw(0, 0, LJPEG); LPrinter.EndDoc; end; end; ... xFrmPrintSetup.Free; ...
  2. programmerdelphi2k

    Working with PDF files??

    hi @Ian Branch maybe the "easer way" do show your PDF or any other files (extention) registered in your browser, it would be: WebBrowser (old IDEs) or EdgeBrowser (new IDEs) some extentions (or not registered to your browser open) will be "to download file" not to show it! you know... you'll need: web kit for your browser target (im using "Microsoft.WebView2.FixedVersionRuntime.111.0.1661.54.x64.cab" library kit from MS) web DLL in your exe folder other way, would be "import a ActiveX from Adobe (for example) into your IDE and use this new component... but all target-PC needs have Adobe installed" here my sample using EdgeBrowser components in RAD 11.3 do open a PDF file ... Vcl.Edge; type TForm1 = class(TForm) EdgeBrowser1: TEdgeBrowser; Button1: TButton; procedure Button1Click(Sender: TObject); end; var Form1: TForm1; implementation {$R *.dfm} procedure TForm1.Button1Click(Sender: TObject); begin EdgeBrowser1.Navigate('file://d:\p1.pdf') end; end.
  3. programmerdelphi2k

    Print a jpeg from a table blob field?

    look this https://stackoverflow.com/questions/38904160/why-is-tprinter-xe7-suddenly-having-problems-today
  4. programmerdelphi2k

    Print a jpeg from a table blob field?

    a simple... maybe? LPrinter := TPrinter.Create; try LPrinter.PrinterIndex := -1; // current printer ( if any one ??? ) LPrinter.BeginDoc; LPrinter.Canvas.TextOut(0, 0, 'Hello there...'); LPrinter.EndDoc; finally LPrinter.Free; end;
  5. programmerdelphi2k

    Print a jpeg from a table blob field?

    very weird... did try run app out-of-IDE?
  6. programmerdelphi2k

    Print a jpeg from a table blob field?

    Any printing progress, or is it just stuck? Does your app need any privileges to complete the print?
  7. programmerdelphi2k

    Print a jpeg from a table blob field?

    did it works?
  8. programmerdelphi2k

    Print a jpeg from a table blob field?

    @Ian Branch for test: if you try printing (any things) using IDE menu "Print", is it works?
  9. programmerdelphi2k

    Print a jpeg from a table blob field?

    @Ian Branch normally, USB/Wifi ports causing problem... try print a "Demo page" (from Driver) for test the communication between PC/Printer if necessary "Create a new port to printer" for tests
  10. programmerdelphi2k

    Print a jpeg from a table blob field?

    try re-install drivers again!!!
  11. programmerdelphi2k

    Print a jpeg from a table blob field?

    try my sample, and see the resulted... in my PDF printer works good!
  12. programmerdelphi2k

    Print a jpeg from a table blob field?

    are you deleting your file here?
  13. programmerdelphi2k

    Print a jpeg from a table blob field?

    hi @Ian Branch try my sample: my "resize proc" it's not reliable ok (but it's good for me), use any other library for better result!!! my Firebird table with a BLOB field storing just "JPEG" for this test (any other type needs re-draw my procedure below) no needs store on file, send it directly to printer! tested in a PDF default printer on MSWin10 -> JPEG 1920x1080 generated a file 707KB. type TForm1 = class(TForm) FDGUIxWaitCursor1: TFDGUIxWaitCursor; FDPhysFBDriverLink1: TFDPhysFBDriverLink; FDConnection1: TFDConnection; FDQuery1: TFDQuery; FDQuery1ID: TIntegerField; FDQuery1MYJPEG: TBlobField; DataSource1: TDataSource; DBGrid1: TDBGrid; ... implementation procedure MyResizeBitmap2( { } const AJPEGsource: TJPEGImage; { } const ABitmapTarget: TBitmap; { } const LPrinterPageWidth: integer; { } const LPrinterPageHeigth: integer; { } const AScaled: boolean); var ANewWidth : integer; ANewHeight: integer; // LPrinterScale: double; // LJPEGWidth : integer; LJPEGHeight: integer; // LScaleW: double; LScaleH: double; begin LJPEGWidth := AJPEGsource.Width; LJPEGHeight := AJPEGsource.Height; LPrinterScale := 1; // if AScaled then begin LScaleW := LPrinterPageWidth / LJPEGWidth; if (LJPEGWidth > LPrinterPageWidth) then LScaleW := LJPEGWidth / LPrinterPageWidth; // LScaleH := LPrinterPageHeigth / LJPEGHeight; if (LJPEGHeight > LPrinterPageHeigth) then LScaleH := LJPEGHeight / LPrinterPageHeigth; // LPrinterScale := LScaleW; if LScaleW > LScaleH then LPrinterScale := LScaleH; end; // ANewWidth := Trunc(AJPEGsource.Width * LPrinterScale); ANewHeight := Trunc(AJPEGsource.Height * LPrinterScale); // { Form1.Memo1.Lines.Add('-----------'); Form1.Memo1.Lines.Add(format('Printer: W=%d, H=%d', [LPrinterPageWidth, LPrinterPageHeigth])); Form1.Memo1.Lines.Add(format('Printer scales: %f', [LPrinterScale])); Form1.Memo1.Lines.Add(format('New W=%d, H=%d', [ANewWidth, ANewHeight])); } // ABitmapTarget.PixelFormat := pf24bit; ABitmapTarget.Width := ANewWidth; ABitmapTarget.Height := ANewHeight; // ABitmapTarget.Canvas.StretchDraw(Rect(0, 0, ANewWidth, ANewHeight), AJPEGsource); // AJPEGsource.Assign(ABitmapTarget); end; procedure TForm1.Button3Click(Sender: TObject); var // temp for memory works... LPrinter : TPrinter; LJPEG : TJPEGImage; LJPEGStream : TMemoryStream; LBitmapToResize: TBitmap; begin LJPEGStream := TMemoryStream.Create; LJPEG := TJPEGImage.Create; LBitmapToResize := TBitmap.Create(1, 1); try // my field BLOB with only "JPEG" files!!! any other raise an exception!!! // header: ($FF, $D8, $FF); // 255, 216, 255 FDQuery1MYJPEG.SaveToStream(LJPEGStream); // LJPEGStream.Position := 0; LJPEG.LoadFromStream(LJPEGStream); // Memo1.Text := format('JPEG: %dx%d', [LJPEG.Width, LJPEG.Height]); // if not(LJPEG.Empty) then begin LPrinter := TPrinter.Create; try LPrinter.PrinterIndex := -1; // current printer ( if any one ??? ) LPrinter.Orientation := TPrinterOrientation(integer(not chkbxPortrait.Checked)); // // try resize to fill the page on printing... MyResizeBitmap2( { } LJPEG, { } LBitmapToResize, { } GetDeviceCaps(LPrinter.Handle, HORZRES), { } GetDeviceCaps(LPrinter.Handle, VERTRES), { } chkbxScaled.Checked); // Memo1.Lines.Add(format('JPEG loaded: %dx%d', [LJPEG.Width, LJPEG.Height])); // LPrinter.BeginDoc; LPrinter.Canvas.Draw(0, 0, LJPEG); LPrinter.EndDoc; finally LPrinter.Free; end; end; finally LBitmapToResize.Free; LJPEG.Free; LJPEGStream.Free; end; end;
  14. programmerdelphi2k

    Print a jpeg from a table blob field?

    basically, you would can read your field using TBLOBField class that is present in any Dataset see : https://docwiki.embarcadero.com/Libraries/Sydney/en/Data.DB.TDataSet.CreateBlobStream later that, you can send the stream to another target to process it
  15. programmerdelphi2k

    ScoreBoard StopWatch

    @Andry try some like this implementation {$R *.dfm} uses System.DateUtils; var LRigthEndTime : TDateTime; LLeftEndTime : TDateTime; LCurrentTime : TDateTime; // the start value... LDirectionTimer: boolean = true; // true = to right, false = to left LGameOver : boolean = false; procedure MyResetTimes; begin // // define your initial values in some place... // just for my test in my OnCreate on form // Form1.Timer1.Enabled := false; // LCurrentTime := now; // StrToDateTime('xx/xx/xxxx 00:00:00'); LRigthEndTime := LCurrentTime; LLeftEndTime := LCurrentTime; // LRigthEndTime.AddSecond(10); // StrToDateTime('xx/xx/xxxx 00:00:00'); LLeftEndTime.AddSecond(-10); // StrToDateTime('xx/xx/xxxx 23:59:59'); // // here, it's dependent of your direction usage: LGameOver := (LRigthEndTime <= LCurrentTime) { or (LLeftEndTime >= LCurrentTime) }; // Form1.Memo1.Text := 'End Right: ' + TimeToStr(LRigthEndTime); Form1.Memo1.Lines.Add('End Left: ' + TimeToStr(LLeftEndTime)); Form1.Label1.Caption := TimeToStr(LCurrentTime); Form1.Label2.Caption := DateTimeToStr(LCurrentTime); end; procedure TForm1.FormCreate(Sender: TObject); begin MyResetTimes; end; procedure TForm1.Timer1Timer(Sender: TObject); procedure MyTimeIsOver(const AValue: smallint); begin LCurrentTime.AddSecond(AValue); if (AValue > 0) then Timer1.Enabled := not(LCurrentTime = LRigthEndTime) else Timer1.Enabled := not(LCurrentTime = LLeftEndTime); // LGameOver := Timer1.Enabled = false; end; begin if LDirectionTimer then MyTimeIsOver(1) else MyTimeIsOver(-1); // Label1.Caption := TimeToStr(LCurrentTime); Label2.Caption := DateTimeToStr(LCurrentTime); end; procedure TForm1.BtnTimePLUSClick(Sender: TObject); begin if LGameOver then exit; // LDirectionTimer := true; Timer1.Enabled := not Timer1.Enabled; end; procedure TForm1.BtnTimeMINUSClick(Sender: TObject); begin if LGameOver then exit; // LDirectionTimer := false; Timer1.Enabled := not Timer1.Enabled; end; procedure TForm1.BtnResetTimesClick(Sender: TObject); begin MyResetTimes; end; end.
  16. programmerdelphi2k

    Debug Break Point

    more info ( source code it's necessary )... Project->Options-Building->Compiling->Optimization = false DCU should be compiled in "Debug mode" to produce info object shoud be in use in some code point... else, compiler try ignore it
  17. programmerdelphi2k

    Radio button options not remembered on re-opening app

    @Willicious look, I see above you only "get/set" values to/from your properties and RgButtons... it's necessary know "how do you "SAVE/LOAD" this values... or be, are you saving in "disk", "Registry", etc... how do you do? look, when you change the value in your Class-Game or RgButtons, this stay only on memory while you app is running, nothing more... you needs save in disk or Registry, then you will can "Load" for your RgButtons again, not in Class-Game, you got it? did you try my sample above?
  18. programmerdelphi2k

    Radio button options not remembered on re-opening app

    side-effect: If a component found in the file does not exist in your form, for example, it will be created! So check before taking any actions!
  19. programmerdelphi2k

    Radio button options not remembered on re-opening app

    @Willicious try some like this: type TForm1 = class(TForm) RadioGroup1: TRadioGroup; Button1: TButton; Memo1: TMemo; BtnLoadRadioButtons: TButton; BtnSaveRadioButtons: TButton; procedure BtnLoadRadioButtonsClick(Sender: TObject); procedure BtnSaveRadioButtonsClick(Sender: TObject); private procedure MySaveRadioGroup; procedure MyLoadRadioGroup; public { Public declarations } end; var Form1: TForm1; implementation {$R *.dfm} (* 0) Adapt your class to handle the desired components! 1) always try actions in "Try...Except" block! 2) in Form creating, your controls may not have been created yet!!! *) procedure TForm1.MySaveRadioGroup; var LMemStream: TMemoryStream; LControl : TControl; begin // TRY... EXCEPT ... END!!! LMemStream := TMemoryStream.Create; try for var i: integer := 0 to (RadioGroup1.ControlCount - 1) do begin LControl := RadioGroup1.Controls[i]; LMemStream.WriteComponent(LControl); end; // LMemStream.SaveToFile('MyRadioButtonsSavedOnDisk.bin'); finally LMemStream.Free; end; end; procedure TForm1.MyLoadRadioGroup; var LMemStream: TMemoryStream; LControl : TControl; begin // TRY... EXCEPT ... END!!! if FileExists('MyRadioButtonsSavedOnDisk.bin') then begin LMemStream := TMemoryStream.Create; try LMemStream.LoadFromFile('MyRadioButtonsSavedOnDisk.bin'); // for var i: integer := 0 to (RadioGroup1.ControlCount - 1) do begin LControl := RadioGroup1.Controls[i]; LMemStream.ReadComponent(LControl); // // TGroupButton = class(TRadioButton) on "implementation seccion" // TGroupButton is a "internal" type to TRadioButton usage!!! Memo1.Lines.Add(LControl.ClassName); end; finally LMemStream.Free; end; end else ShowMessage('File not found!'); end; procedure TForm1.BtnLoadRadioButtonsClick(Sender: TObject); begin MyLoadRadioGroup; end; procedure TForm1.BtnSaveRadioButtonsClick(Sender: TObject); begin MySaveRadioGroup; end; end.
  20. programmerdelphi2k

    Delphi 11.3 is available now!

    Did you mean? "Ctrl+ClickMouse"? it works if you has a source code on the "Browse Path" or unit PAS in your project-folder if the "object clicked" it's a "interfaced", you go to the interface if the "object clicked" it's a "class concrete", you go to the class
  21. programmerdelphi2k

    Quite confused about how to save a project

    you dont needs, in fact, because you have "Project Manager", just select the file (unit) and press F2 or right-click Rename!
  22. programmerdelphi2k

    Split string on whitespace

    would be that? procedure TForm1.Button1Click(Sender: TObject); var LText : string; LArrStr: TArray<string>; begin LText := 'Hello World'#9' . . Delphi in'#32'Action'; // 2x spaces LArrStr := LText.Split([' ' {, #9, #32}] { , TStringSplitOptions.ExcludeEmpty } ); // Array with 2 items... // 1x space LArrStr := LText.Split([' ', #9, #32] { , TStringSplitOptions.ExcludeEmpty } ); // Array with 9 items... Memo1.Lines.AddStrings(LArrStr); end;
  23. programmerdelphi2k

    Query result to dynamic array

    type TMyRecToStoreSomeValues = record ValInt: integer; ValString: string; ValDate: TDate; // etc... end; TMyValuesInArray = TArray<TMyRecToStoreSomeValues>; function HelloWorld: TMyValuesInArray; var LMyValue : TMyRecToStoreSomeValues; LMyValues: TMyValuesInArray; begin LMyValues := []; // // ... // result := LMyValues; // of course, dont abuse this... like result = 1.000.000.000.000 records :) when all end, free it on "target" end;
  24. programmerdelphi2k

    Query result to dynamic array

    For simpler code (without using complex business rules, classes, rtti, etc...), you could create a "record TYPE" with all values "type" that you need to store in your Array, then, you need verify "where store this, where store that"... type type TMyRecToStoreSomeValues = record ValInt: integer; ValString: string; ValDate: TDate; // etc... end; procedure TForm1.Button1Click(Sender: TObject); var LMyValue : TMyRecToStoreSomeValues; LMyValues: TArray<TMyRecToStoreSomeValues>; begin myTable.First; // after your filters... // while not myTable.EOF do begin for var F in myTable.Fields do begin if F.DisplayName = 'hello' then LMyValue.ValInt := F.AsInteger; if F.DisplayName = 'world' then LMyValue.ValString := F.AsString; if F.DisplayName = 'Delphi' then LMyValue.ValDate := F.AsDateTime; end; // LMyValues := LMyValues + [LMyValue]; // myTable.NEXT; end; // // reading... for example for var V in LMyValues do Memo1.Lines.Add( { } V.ValInt.ToString + ' ' + V.ValString + ' ' + DateToStr(V.ValDate) { } ); end;
  25. programmerdelphi2k

    Displaying an independent background in a Delphi app

    @Willicious maybe some like this: var LBackgroundBitmap: TBitmap; procedure MyLoadBackgroundBitmap; begin LBackgroundBitmap := TBitmap.Create; LBackgroundBitmap.LoadFromFile('Background.bmp'); // use a picture with same size than "your screen"! // // -- try save resource/memory -- needs tests if works or not? // LBackgroundBitmap.Dormant; // Free up GDI resources // LBackgroundBitmap.FreeImage; // Free up Memory... dont lose the bitmap! // // ....... LBackgroundBitmap.ReleaseHandle; // This will actually lose the bitmap! end; procedure MyFreeBackgroundBitmap; begin LBackgroundBitmap.Free; end; procedure TForm1.FormPaint(Sender: TObject); begin if (LBackgroundBitmap <> nil) and not(LBackgroundBitmap.Empty) then begin Canvas.Brush.Bitmap := LBackgroundBitmap; Canvas.FillRect(Rect(0, 0, Width, Height)); // Canvas.Draw(0, 0, LBackgroundBitmap); end; end; initialization MyLoadBackgroundBitmap; finalization MyFreeBackgroundBitmap; end.
×