When using DCEF3 TChromium, how can i keep the session alive ?
For instance, if i go to a web-site and login on it, when i close my app and open it again, i need to login again. I want to keep the session alive, just like it would be if i use Google Chrome.
I tried to add 'CefLib' on my app 'uses' clause and set 'CefCache' like the code below, but although i can see files being stored on 'cookies' folder, it seems to make no difference in keeping the session alive :
program Project1;
uses
Forms,
Unit1 in 'Unit1.pas' {Form1},
ceflib in 'C:\app\dcef\src\ceflib.pas';
{$R *.res}
begin
CefCache := 'cookies';
Application.Initialize;
Application.MainFormOnTaskbar := True;
Application.CreateForm(TForm1, Form1);
Application.Run;
end.
Thanks in advance.
A guy form the official's DCEF3 forum provided the solution below, tested and approved !
CookieManager: ICefCookieManager;
FormCreate:
begin
CookiesPath := ExtractFilePath(Application.ExeName) + 'cookies';
CookieManager := TCefCookieManagerRef.Global(nil);
CookieManager.SetStoragePath(CookiesPath, True, nil);
end;
FormClose:
begin
CookieManager.FlushStore(nil);
end
Related
I want to force my application to always use the Spanish regional settings, using the FormatSettings global variable, but the application ignores those settings. Do you know what I have missed ?.
program TestProject;
uses
Vcl.Forms,
SysUtils,
Rutinas in 'Rutinas.pas',
Conexion in 'Conexion.pas' {dmConexion: TDataModule},
MainForm in 'MainForm.pas' {frmMainForm};
{$R *.res}
begin
Application.Initialize;
FormatSettings := TFormatSettings.Create('es-ES');
Application.MainFormOnTaskbar := True;
Application.Title := Application_Name;
Application.CreateForm(TdmConexion, dmConexion);
Application.CreateForm(TfrmMainForm, frmMainForm);
Application.Run;
end.
Thank you.
PS: I know that FormatSettings is not recommended because it's not thread safe, but it shouldn't be a problem here because I only change it once at the application start up, any other time that I need a customized conversion I use a local TFormatSettings variable.
I apologize, the problem wasn't in Delphi but on the DevExpress controls that I use to present the data.
DevExpress uses their own format settings: https://www.devexpress.com/Support/Center/Question/Details/A517/how-to-use-custom-formats-for-editors
Now this works correctly :
program TestProject;
uses
Vcl.Forms,
SysUtils,
cxFormats,
Rutinas in 'Rutinas.pas',
Conexion in 'Conexion.pas' {dmConexion: TDataModule},
MainForm in 'MainForm.pas' {frmMainForm};
{$R *.res}
begin
Application.Initialize;
FormatSettings := TFormatSettings.Create('es-ES');
Application.UpdateFormatSettings := False;
cxFormatController.BeginUpdate;
cxFormatController.UseDelphiDateTimeFormats := True;
cxFormatController.EndUpdate;
cxFormatController.GetFormats;
cxFormatController.NotifyListeners;
Application.MainFormOnTaskbar := True;
Application.Title := Application_Name;
Application.CreateForm(TdmConexion, dmConexion);
Application.CreateForm(TfrmMainForm, frmMainForm);
Application.Run;
end.
Instead of using the png images through the project options for a splashscreen I want to use my own Form for a splashscreen.
I've found a solution for XE2 in the following link, but it doesn't work for Delphi 10 Seattle: https://stackoverflow.com/a/9080804/2728408
Below I have some examples I've tried in my project .dpr:
Example 1:
program Project2;
uses
FMX.Forms,
System.SysUtils,
Unit1 in 'Unit1.pas' {MainForm},
Unit2 in 'Unit2.pas' {SplashForm};
{$R *.res}
begin
Application.Initialize;
SplashForm := TSplashForm.Create(nil);
SplashForm.Show;
Application.ProcessMessages;
Sleep(1000); // Whatever to control display time of splash screen
Application.CreateForm(TMainForm, MainForm);
SplashForm.Close;
SplashForm.Free;
Application.Run;
end.
Example 2:
program Project2;
uses
FMX.Forms,
System.SysUtils,
Unit1 in 'Unit1.pas' {MainForm},
Unit2 in 'Unit2.pas' {SplashForm};
{$R *.res}
begin
Application.Initialize;
Application.CreateForm(TSplashForm, SplashForm);
Application.Run;
Sleep(1000);
Application.Terminate;// Also tried Application.Destroy
Application.Initialize;
Application.CreateForm(TMainForm, MainForm);
Application.Run;
end.
Example 3:
program Project2;
uses
FMX.Forms,
System.SysUtils,
Unit1 in 'Unit1.pas' {MainForm},
Unit2 in 'Unit2.pas' {SplashForm};
{$R *.res}
begin
Application.Initialize;
Application.CreateForm(TSplashForm, SplashForm);
Application.Run;
Sleep(1000);
Application.CreateForm(TMainForm, MainForm);
SplashForm.Close;
Application.ProcessMessages;
Application.Run;
end.
Anyone has a solution to my problem?
you should not interfere with Application.Terminare/Inititalse the way you do it in the code.
In Firemonkey, you can change the main form of the application in runtime. So, you should show your splash form first, do all the job you want and then switch to your main form.
See this for an example: http://www.uweraabe.de/Blog/2016/01/22/a-splash-form-in-firemonkey/
procedure TFormSplash.FormCreate(Sender: TObject);
begin
StartupTimer.Enabled := false;
StartupTimer.Interval := 500; // can be changed to improve startup speed in later releases
end;
procedure TFormSplash.SplashImagePaint(Sender: TObject; Canvas: TCanvas; const ARect: TRectF);
begin
StartupTimer.Enabled := not FInitialized;
end;
procedure TFormSplash.StartupTimerTimer(Sender: TObject);
begin
StartupTimer.Enabled := false;
if not FInitialized then begin
FInitialized := true;
LoadMainForm;
end;
end;
procedure TFormSplash.LoadMainForm;
var
form: TForm;
begin
form := TMainForm.Create(Application);
form.Show;
Application.MainForm := form;
Close;
end;
Here is what I have been doing for the past 3 days or so.
First: Create the form of the splash screen. Like normal loading of Delphi/C++ IDE, it has an indicator that "xxxx dll is loading..". So the basic steps are to include the splash screen as part of the usual loading of the main application.
Second: Remember that your DPR file takes a vital role in loading and/or creating all the forms. Although I agree with the VCL function (Application.ProcessMessages) to show to the user that it is creating the form.
Third: Never run a procedure in your Main Form OnCreate Event except for Skinning or to instantiate the skin. But call it again in the DPR once the Main Form is created.
Fourth: Disable first your Main Form once it is created, so that the user will not click on buttons or whatever then re-enable it when the Splash Screen is hidden.
Here is the DPR:
program xxxx;
uses
Forms, MidasLib,.....
{$R *.res}
begin
Application.Initialize;
Application.MainFormOnTaskbar := True;
Application.Title := 'xxxxx';
SplashFrm := TSplashFrm.Create(Application);
try
Application.CreateForm(TMain_Form, Main_Form);
Main_Form.Skinning;
Application.ProcessMessages;
SplashFrm.FormStyle := TFormStyle.fsStayOnTop;
Main_Form.Enabled := False;
Main_Form.WindowState := TWindowState.wsMaximized;
Application.ProcessMessages;
SplashFrm.Show; //Never use showModal coz splash form needs to be closed first and create all the rest of the forms.
SplashFrm.Label5.Caption := 'Loading... Database handlers..';
Application.CreateForm(TDM, DM);
Application.ProcessMessages;
SplashFrm.Label5.Caption := 'Loading... Login Libraries..';
Application.CreateForm(TLogin_Frm, Login_Frm);
Application.ProcessMessages;
.....// All the rest of the Forms.
Main_Form.DSiTrimWorkingSet; //[StockOverflow/questions/2031577][1]
finally
SplashFrm.Free;
Main_Form.Check_Registration;
Main_Form.Checking_Internet_Proc;
Main_Form.Enabled := True;
Main_Form.sStatusBar1.Panels[0].Text := 'Ready...';
Application.ProcessMessages;
Main_Form.DSiTrimWorkingSet;
end;
Application.Run;
end.
Is it possible to choose a form (as a mainform) from a list of "available" forms after connecting to the database ? I have a datamodule with 3 'available' forms.No mainform for the time being.Datamodule is created first. Now, I would like to select the form depending on the database the user logs in to, and make it the mainform. Can this be done and how ?
You can easily do something like that in the DPR.
program Project1;
uses
Forms,
Unit1 in 'Unit1.pas' {Form1},
Unit2 in 'Unit2.pas' {DM1: TDataModule},
Unit3 in 'Unit3.pas' {Form2};
{$R *.res}
begin
Application.Initialize;
Application.CreateForm(TDM1, DM1);
case DM1.ChooseForm of
1: Application.CreateForm(TForm1, Form1);
else Application.CreateForm(TForm2, Form2);
end;
Application.Run;
end.
In this example you first create the datamodule. When it's created you can use the logic in the datamodule. In the datamodule I made a public function that returns an integer to determine which form to load. (In practice I would not rely on magic numbers)
The main form is deemed to be the first form created by a call to Application.CreateForm. So add your selection logic to the .dpr file code, and then call Application.CreateForm to create whichever form the user selects.
// .dpr code
begin
Application.Initialize;
CreateMainForm;
Application.Run;
end.
Here, CreateMainForm is provided by you and implements the user form selection. It might go like this:
procedure CreateMainForm;
var
Form: TForm;
FormClass: TFormClass;
begin
FormClass := ChooseMainFormClass;
Application.CreateForm(FormClass, Form);
end;
Again, ChooseMainFormClass is provided by you.
This question already has answers here:
Closed 11 years ago.
Possible Duplicate:
How to minimize a window to the taskbar? (i.e. not iconify)
I want to show some form before showing the main form in my app, I do:
program Project1;
uses
Forms,
Unit1 in 'Unit1.pas' {Form1},
Unit2 in 'Unit2.pas' {Form2};
{$R *.res}
begin
with TForm2.Create(Application) do
try
ShowModal;
finally
Free;
end;
Application.Initialize;
Application.MainFormOnTaskbar := True;
Application.CreateForm(TForm1, Form1);
Application.Run;
end.
It's working properly but when I minimizing first form (TForm2) it's doing something like this (not minimizing to taskbar):
What's wrong?
Try to Hide it before you Free first. I don't know but if your first form is an authentication form maybe you could also use ModalResult to be sure that the user's response was ok.
Hope this helps.
in my project i have two form's(form1,form2), form1 is configuration form.
i want to show Form1 and when we click Button1 then show Form2 and free(Release) Form1. how can to i do this?
i use this code. but this project start and then exit automatically.A Friend said because the application message loop never start, and application terminates because main form does not exist. how i can to solve this problem?
uses Unit2;
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
begin
Application.CreateForm(TForm2, Form2);
Release;
end;
///
program Project1;
uses
Forms,
Unit1 in 'Unit1.pas' {Form1},
Unit2 in 'Unit2.pas' {Form2};
{$R *.res}
begin
Application.Initialize;
Application.MainFormOnTaskbar := True;
Form1:= TForm1.Create(Application);
Application.Run;
end.
Do exactly what you asked in the question title: Create and show the configuration form, and then create and show the main form. The trick is in how you create them. Only use Application.CreateForm for the one form that you want to be your main form. Use the ordinary object creation technique for all other forms.
Modify your DPR file like so:
var
ConfigForm: TConfigForm;
begin
Application.Initialize;
ConfigForm := TConfigForm.Create(nil);
try
if ConfigForm.ShowModal <> mrOK then
exit;
finally
ConfigForm.Free;
end;
Application.CreateForm(TMainForm, MainForm);
Application.Run;
end.
You need to create Form2 first and this will be your main form. You want it to start hidden and be shown after Form1 has done its job. Something like this:
uses Unit2;
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
begin
Form2.Show;
Release;
end;
///
program Project1;
uses
Forms,
Unit1 in 'Unit1.pas' {Form1},
Unit2 in 'Unit2.pas' {Form2};
{$R *.res}
begin
Application.Initialize;
Application.MainFormOnTaskbar := True;
Application.CreateForm(TForm2, Form2);
Form2.Hide;
Form1 := TForm1.Create(Application);
Form1.Show;
Application.Run;
end.
The reason is that the app terminates when your main form closes. And your main form is typically the first one that you create.
You can prohibit Form1 to be shown by setting ShowMainForm to false. Leave the code in the DPR just as the IDE creates it:
uses
Forms,
Unit2 in 'Unit2.pas' {Form2},
Unit1 in 'Unit1.pas' {Form1};
{$R *.res}
begin
Application.Initialize;
Application.MainFormOnTaskbar := True;
Application.CreateForm(TForm1, Form1);
Application.CreateForm(TForm2, Form2);
Application.Run;
end.
In the FormCreate event of Form2 just set ShowMainForm to false and call Show to make Form2 visible:
procedure TForm2.FormCreate(Sender: TObject);
begin
Application.ShowMainForm := False;
Show;
end;
and in the ButtonClick event of Form2 show Form1 and close Form2:
procedure TForm2.Button1Click(Sender: TObject);
begin
Form1.Show;
Close;
end;
This keeps all necessary changes inside unit2.
Edit
Some remarks that came to mind after sleeping a night over it:
Form2 should be the last one auto-created, i.e. the one directly before the Application.Run statement.
The Form1.Show statement in the ButtonClick event should be moved to the FormClose event. Thus the user can close the form with the Windows close button or whatever he likes best.
If for some reason Form1 should never be shown, some code must be added to close the application. A Halt may serve here.