[solved] is there a non visual open dialog?! lazarus / 21-General ---------------------------------------------------------------------- Nicole · 2025-04-12 14:04 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. ---------------------------------------------------------------------- sstvmaster · 2025-04-12 18:13 Not directly a non-visual unit, but maybe TStringStream or TFileStream can help? Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i program project1; usesClasses, sysutils; var  fStringStream: TStringStream;  fFileStream: TFileStream;  txt: String; begin   WriteLn(' *** TStringStream ***');  fStringStream := TStringStream.Create('', TEncoding.UTF8);  try    fStringStream.LoadFromFile('test.txt');    WriteLn(fStringStream.DataString);  finally    fStringStream.Free;  end;   WriteLn();  WriteLn(' *** TFileStream ***');   fFileStream := TFileStream.Create('test.txt', fmOpenRead or fmShareDenyWrite);  try  SetLength(txt, fFileStream.Size);    fFileStream.Read(txt[1], fFileStream.Size);    WriteLn(txt);  finally    fFileStream.Free;  end;   ReadLn;end. ---------------------------------------------------------------------- jamie · 2025-04-12 18:32 The slow scan tv master at it again ---------------------------------------------------------------------- sstvmaster · 2025-04-12 19:04 i never was gone. ---------------------------------------------------------------------- cdbc · 2025-04-15 09:01 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 ---------------------------------------------------------------------- wp · 2025-04-15 09:25 Quote from: Nicole on April 12, 2025, 04:04:49 pmI 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][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i function OpenFileDialog(var FileName: String; Filter: String; Options: TOpenOptions): Boolean;var  dlg: TOpenDialog;begin  dlg := TOpenDialog.Create(nil);  try    dlg.FileName := FileName;    dlg.Filter := String;    dlg.Options := Options;    Result := dlg.Execute;    if Result then FileName := dlg.FileName;  finally    dlg.Free;  end;end; ---------------------------------------------------------------------- cdbc · 2025-04-15 10:31 Hi Right, so @wp was way faster, but anyway - here's my little example on how it also could be done... Attached. Regards Benny ---------------------------------------------------------------------- dsiders · 2025-04-15 15:13 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. ---------------------------------------------------------------------- d2010 · 2025-04-30 12:01 Quote from: dsiders on April 15, 2025, 05:13:26 pmThere 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. ---------------------------------------------------------------------- Martin_fr · 2025-04-30 19:13 Quote from: Nicole on April 12, 2025, 04:04:49 pmI 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][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i type  TPromptUserForFileOpenCallback = function(....): filename;  // pass in whatever is needed to display the dlg / use "out" param for multiple return... var  PromptUserForFileOpenCallback: TPromptUserForFileOpenCallback;  You app can set the variable to its implementation of the dialog. The code in the unit just calls the callback in the variable.