Recent

Author Topic: [solved] is there a non visual open dialog?!  (Read 946 times)

Nicole

  • Hero Member
  • *****
  • Posts: 1095
[solved] is there a non visual open dialog?!
« on: April 12, 2025, 04:04:49 pm »
I use a unit, which is not visual, it is a tool-kit mostly for files etc.

There I need an open dialog.  Otherwise I must shift all the open dialogs to all Frames, which use this unit. Or shift it in just one of them, which is puzzling on working on after a while.

So my question:
Is there a way to add an open dialog to an non-visual unit?




Thank you for all answers!
The solution which runs in my source code now is the "create" thing.
« Last Edit: April 17, 2025, 06:11:27 pm by Nicole »

sstvmaster

  • Sr. Member
  • ****
  • Posts: 305
Re: is there a non visual open dialog?!
« Reply #1 on: April 12, 2025, 08:13:09 pm »
Not directly a non-visual unit, but maybe TStringStream or TFileStream can help?

Code: Pascal  [Select][+][-]
  1. program project1;
  2.  
  3. uses
  4. Classes, sysutils;
  5.  
  6. var
  7.   fStringStream: TStringStream;
  8.   fFileStream: TFileStream;
  9.   txt: String;
  10.  
  11. begin
  12.  
  13.   WriteLn(' *** TStringStream ***');
  14.   fStringStream := TStringStream.Create('', TEncoding.UTF8);
  15.   try
  16.     fStringStream.LoadFromFile('test.txt');
  17.     WriteLn(fStringStream.DataString);
  18.   finally
  19.     fStringStream.Free;
  20.   end;
  21.  
  22.   WriteLn();
  23.   WriteLn(' *** TFileStream ***');
  24.  
  25.   fFileStream := TFileStream.Create('test.txt', fmOpenRead or fmShareDenyWrite);
  26.   try
  27.     SetLength(txt, fFileStream.Size);
  28.     fFileStream.Read(txt[1], fFileStream.Size);
  29.     WriteLn(txt);
  30.   finally
  31.     fFileStream.Free;
  32.   end;
  33.  
  34.   ReadLn;
  35. end.  
  36.  
« Last Edit: April 12, 2025, 08:28:14 pm by sstvmaster »
greetings Maik

Windows 10,
- Lazarus 3.6 (stable) + fpc 3.2.2 (stable)
- Lazarus 4.99 (trunk) + fpc 3.3.1 (main/trunk)

jamie

  • Hero Member
  • *****
  • Posts: 6888
Re: is there a non visual open dialog?!
« Reply #2 on: April 12, 2025, 08:32:59 pm »
The slow scan tv master at it again
The only true wisdom is knowing you know nothing

sstvmaster

  • Sr. Member
  • ****
  • Posts: 305
Re: is there a non visual open dialog?!
« Reply #3 on: April 12, 2025, 09:04:14 pm »
i never was gone. :D
greetings Maik

Windows 10,
- Lazarus 3.6 (stable) + fpc 3.2.2 (stable)
- Lazarus 4.99 (trunk) + fpc 3.3.1 (main/trunk)

cdbc

  • Hero Member
  • *****
  • Posts: 2127
    • http://www.cdbc.dk
Re: is there a non visual open dialog?!
« Reply #4 on: April 15, 2025, 11:01:33 am »
Hi
Yes, it can be done, the question is: How advanced would you like it to be?!?

Make a callback function in the GUI, that you can call into from the 'non-visual' unit behind the scenes, like a service...
I might be able to whip up a quick example...
Regards Benny
If it ain't broke, don't fix it ;)
PCLinuxOS(rolling release) 64bit -> KDE5 -> FPC 3.2.2 -> Lazarus 3.6 up until Jan 2024 from then on it's both above &: KDE5/QT5 -> FPC 3.3.1 -> Lazarus 4.99

wp

  • Hero Member
  • *****
  • Posts: 12792
Re: is there a non visual open dialog?!
« Reply #5 on: April 15, 2025, 11:25:46 am »
I use a unit, which is not visual, it is a tool-kit mostly for files etc.

There I need an open dialog.  Otherwise I must shift all the open dialogs to all Frames, which use this unit. Or shift it in just one of them, which is puzzling on working on after a while.

So my question:
Is there a way to add an open dialog to an non-visual unit?
I am not sure what you mean. My straightforward answer would be: Write a function which creates a TOpenDialog, gets the filename and the options as parameters and returns false if no file has been selected:
Code: Pascal  [Select][+][-]
  1. function OpenFileDialog(var FileName: String; Filter: String; Options: TOpenOptions): Boolean;
  2. var
  3.   dlg: TOpenDialog;
  4. begin
  5.   dlg := TOpenDialog.Create(nil);
  6.   try
  7.     dlg.FileName := FileName;
  8.     dlg.Filter := String;
  9.     dlg.Options := Options;
  10.     Result := dlg.Execute;
  11.     if Result then FileName := dlg.FileName;
  12.   finally
  13.     dlg.Free;
  14.   end;
  15. end;
« Last Edit: April 15, 2025, 01:26:19 pm by wp »

cdbc

  • Hero Member
  • *****
  • Posts: 2127
    • http://www.cdbc.dk
Re: is there a non visual open dialog?!
« Reply #6 on: April 15, 2025, 12:31:34 pm »
Hi
Right, so @wp was way faster, but anyway - here's my little example on how it also could be done... Attached.
Regards Benny
If it ain't broke, don't fix it ;)
PCLinuxOS(rolling release) 64bit -> KDE5 -> FPC 3.2.2 -> Lazarus 3.6 up until Jan 2024 from then on it's both above &: KDE5/QT5 -> FPC 3.3.1 -> Lazarus 4.99

dsiders

  • Hero Member
  • *****
  • Posts: 1403
Re: is there a non visual open dialog?!
« Reply #7 on: April 15, 2025, 05:13:26 pm »
There is also the aggpas components. And a somewhat dated comparison between aggpas and BGRABitmap at https://forum.lazarus.freepascal.org/index.php?topic=33256.0.

I don't use it... so I can't comment on effeciency.
Preview the next Lazarus documentation release at: https://dsiders.gitlab.io/lazdocsnext

d2010

  • Full Member
  • ***
  • Posts: 159
Re: is there a non visual open dialog?!
« Reply #8 on: April 30, 2025, 02:01:07 pm »
There is also the aggpas components. And a somewhat dated comparison between aggpas and BGRABitmap at https://forum.lazarus.freepascal.org/index.php?topic=33256.0.
I don't use it... so I can't comment on effeciency.
I hope I do not spam, this topic.
Here you view OpenDialog and QuickView.
Is very efficients, for files *.sld , because many times  , sometimes have
small-size , little < 512ko. Perhaps other file type, need insert at the end-of-file
, many times, the user/s can append "Thumbnail" or * small-icon/s 256x 256
for quick-demo.
« Last Edit: April 30, 2025, 02:04:44 pm by d2010 »

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 11139
  • Debugger - SynEdit - and more
    • wiki
Re: [solved] is there a non visual open dialog?!
« Reply #9 on: April 30, 2025, 09:13:11 pm »
I use a unit, which is not visual, it is a tool-kit mostly for files etc.

There I need an open dialog.  Otherwise I must shift all the open dialogs to all Frames, which use this unit. Or shift it in just one of them, which is puzzling on working on after a while.

So my question:
Is there a way to add an open dialog to an non-visual unit?

Technically you can use TOpenDialog in any unit:
- you must add the dependencies to the LCL to the project or package in which that unit is.
- but you do NOT need an lfm or design form. You can create it from code.



If you don't want to have the dependencies because your package is not otherwise needing it, then add some kind of callback

in your unit
Code: Pascal  [Select][+][-]
  1. type
  2.   TPromptUserForFileOpenCallback = function(....): filename;  // pass in whatever is needed to display the dlg / use "out" param for multiple return...
  3.  
  4. var
  5.   PromptUserForFileOpenCallback: TPromptUserForFileOpenCallback;
  6.  

You app can set the variable to its implementation of the dialog.

The code in the unit just calls the callback in the variable.

 

TinyPortal © 2005-2018