![]() |
FormShow mit CoolTrayIcon dauert zu lange
Hallo,
hab in meinem Programm die Komponente CoolTrayIcon eingebaut. Wenn ich das Programm minimiere und dann wieder maximiere bzw. anzeige, dauert es so lange bis die .ini-Datei mit allein Einstellungen eingelesen wird, es geschieht in FormShow bei mir. Wer weiß wie man das Problem lösen kann? Die .ini in FormCreate einlesen? Darf man das überhaupt, denn nach dem Laden gleich die Abfrage statt findet, wie das Form dargestellt werden soll usw. und das klappt ab und zu nicht, da Form noch gar nicht createt ist, oder? :gruebel: |
Re: FormShow mit CoolTrayIcon dauert zu lange
FormShow ist eindeutig die falsche stelle denn das wird mehrmalig ausgeführt, eben immer bei einem Show.
OnCreate des Forms könnte übrigens auch "OnAfterCreate" heißen, dann wäre eindeutiger das zu diesem Zeitpunkt der Erstellungsvorgang so gut wie abgeschlossen ist. |
Re: FormShow mit CoolTrayIcon dauert zu lange
Oh.. hab dieses Ereignis nicht, hab Delphi 7PE :gruebel:
Hilft es wenn ich die .ini in OnCreate lade und in OnShow auswerte? :gruebel: Oder wird es genau so lange dauern? :gruebel: |
Re: FormShow mit CoolTrayIcon dauert zu lange
Das Ereignis gibt es ja auch nicht,
Zitat:
Gruß Jens |
Re: FormShow mit CoolTrayIcon dauert zu lange
Und in OnShow auswerten, oder wie? Wie macht man das normalerweise, also die Profis?
|
Re: FormShow mit CoolTrayIcon dauert zu lange
Versuche es komplett im OnCreate zu machen. Wie gesagt wird das OnShow-Ereignis öfters ausgeführt, sobald das Fenster angezeigt wird (minimieren -> maximieren -> OnShow).
Das OnCreate-Ereignis wird einmalig aufgerufen und ist daher gut geeignet. |
Re: FormShow mit CoolTrayIcon dauert zu lange
Also,
ich bin auf gar keinen Fall ein Profi. Und ob das so 100% richtig ist, weiß ich auch nicht. Ich kann nur sagen, das ich mit folgendem Code im OnCreate noch nie Probleme hatte.
Delphi-Quellcode:
Auch hier lese ich im oberen Bereich einen Wert aus einer INI-Datei, welche mir gewissen Komponenten Visible setzte soll.
begin
AppDataDir := GetSpecialFolder(CSIDL_COMMON_APPDATA) + strAppDataDir; NetConf := TIniFile.Create(AppDataDir+strNetConf); with NetConf do begin Master := ReadInteger('ALLGEMEIN','MASTER',0); end; NetConf.Free; if Master = 1 then begin Panel14.Visible := false; Panel16.Visible := false; Panel4.Visible := false; ToolButton7.Visible := false; ToolButton8.Visible := false; Einstelleungen1.Visible := false; Optionen1.Visible := false; AnlagenSetup1.Visible := false; TabSheet1.Visible := false; SetConnectionStringDatabase; PSInitStartMaster; end else begin if ServiceGetStatus('', 'FirebirdGuardianDefaultInstance') = 4 then begin MMStatus.Color := clYellow; MMStatus.Text := 'Verbindung getrennt'; SetConnectionStringDatabase; ComLoadSettings; PSInitStartSlave; end else begin TAufDienstWarten.Enabled := true; TTimeOutDienst.Enabled := true; end; end; end; Gruß Jens |
Re: FormShow mit CoolTrayIcon dauert zu lange
@Jens: Wenn du noch try-finally nutzen würdest (Resourcenschutzblöcke), dann ist es noch schöner. Im Falle einer Exception beim Zugriff auf die Ini (ReadInteger) wird die Ini-Datei dann auch freigegeben.
Delphi-Quellcode:
Das nur, damit es Alex richtig macht.
NetConf := TIniFile.Create(AppDataDir+strNetConf);
try with NetConf do begin Master := ReadInteger('ALLGEMEIN','MASTER',0); end; finally NetConf.Free; end; |
Re: FormShow mit CoolTrayIcon dauert zu lange
Ok :-D
Und bei mir sieht das so aus, wenn jemand lust hat guck mal durch, vielleicht gibt's da was zu verbessern. :thumb:
Delphi-Quellcode:
procedure TForm1.FormShow(Sender: TObject);
var ComboIndex: Integer; Ini : TIniFile; UserAppDataDir, ProgPath, Headline: String; begin UserAppDataDir:=GetSpecialFolder(CSIDL_LOCAL_APPDATA); ProgPath:=ExtractFilePath(ParamStr(0)); if FileExists(UserAppDataDir + AppDataRootDir + AppDataProjectDir + '\Config-t.ini') then begin Ini := TIniFile.Create(UserAppDataDir + AppDataRootDir + AppDataProjectDir + '\Config-t.ini'); try Headline := Ini.ReadString('Default', 'Headline', ''); ComboBox1.ItemIndex := Ini.ReadInteger('Default', 'Channel', 1); TrackBar1.Position := Ini.ReadInteger('Default', 'Volume', 90); Form5.cbDirectConnection.Checked := Ini.ReadBool('Default', 'Proxy', True); Form5.ed_ProxyServer.Text := Ini.ReadString('Default', 'ProxyIP', ''); Form1.ClientWidth := Ini.ReadInteger('Default', 'Form', 570); ShowDate1.Checked := Ini.ReadBool('Default', 'ShowDate', False); ShowTime1.Checked := Ini.ReadBool('Default', 'ShowTime', False); ShowPlayTime1.Checked := Ini.ReadBool('Default', 'ShowPlayTime', False); Form3.RadioButton1.Checked := Ini.ReadBool('Default', 'ItemPositionTop', False); Form3.RadioButton2.Checked := Ini.ReadBool('Default', 'ItemPositionBelow', True); Language := Ini.ReadString('Default', 'Language', ''); ListBox1.TopIndex := Ini.ReadInteger('Default', 'Channelposition', 0); Background := Ini.ReadString('Default', 'Background', ''); Form5.CheckBox2.Checked := Ini.ReadBool('Default', 'Traybarwhenmin', False); Form5.LabeledEdit1.Text := Ini.ReadString('Default', 'Headline', ''); finally Ini.Free; end; if Form5.CheckBox2.Checked=True then begin CoolTrayIcon1.Enabled:=True; CoolTrayIcon1.MinimizeToTray:=True; end; ComboIndex:=ComboBox1.ItemIndex; if ShowDate1.Checked=True then begin Label10.Visible:=True; Label10.Caption:=FormatDateTime('dddd, d. mmmm yyyy', date); end else Label10.Visible:=False; if ShowTime1.Checked=True then begin Label11.Visible:=True; Label11.Caption:=FormatDateTime('tt', time); end else Label11.Visible:=False; end; if ShowPlayTime1.Checked=True then begin Image28.Visible:=True; Label6.Visible:=True; end else begin Image28.Visible:=False; Label6.Visible:=False; end; if Form1.ClientWidth=407 then begin Image11.Visible := False; Image10.Visible := True; Label10.Caption:='Label10'; Label10.Left:=348; //344 Label10.Caption:=FormatDateTime('dddd, d. mmmm yyyy', date); Label11.Caption:='Label11'; Label11.Left:=361; //360 Label11.Caption:=FormatDateTime('tt', time); end else begin Image11.Visible := True; Image10.Visible := False; Label10.Caption:='Label10'; Label10.Left:=511; //507 Label10.Caption:=FormatDateTime('dddd, d. mmmm yyyy', date); Label11.Caption:='Label11'; Label11.Left:=524; //523 Label11.Caption:=FormatDateTime('tt', time); end; case ComboBox1.Itemindex of 3: Image9.Visible := False; 7: Image9.Visible := False; 21: Image9.Visible := False; 22: Image9.Visible := False; 24: Image9.Visible := False; 25: Image9.Visible := False; end; vol := TrackBar1.Position; cbDirectConnectionClick(Sender); if Language='English' then begin //Form1 AutoUpgrader1.InfoFileURL:='http://xxx/update/autoupgrade_en.cgi'; Font.Charset := DEFAULT_CHARSET; Label2.Font.Charset := DEFAULT_CHARSET; Label10.Font.Charset := DEFAULT_CHARSET; GroupBox1.Font.Charset := DEFAULT_CHARSET; Label9.Font.Charset := DEFAULT_CHARSET; ComboBox1.Font.Charset := DEFAULT_CHARSET; GroupBox1.Font.Charset := DEFAULT_CHARSET; GroupBox2.Font.Charset := DEFAULT_CHARSET; Label3.Font.Charset := DEFAULT_CHARSET; Label4.Font.Charset := DEFAULT_CHARSET; //? UseLanguage('EN'); RetranslateComponent(Self); English1.Enabled:=False; German1.Enabled:=True; Russian1.Enabled:=True; if ComboBox1.ItemIndex=-1 then ComboBox1.ItemIndex:=ComboIndex; end else if Language='German' then begin //Form1 AutoUpgrader1.InfoFileURL:='http://xxx/update/autoupgrade_en.cgi'; Font.Charset := DEFAULT_CHARSET; Label2.Font.Charset := DEFAULT_CHARSET; Label10.Font.Charset := DEFAULT_CHARSET; GroupBox1.Font.Charset := DEFAULT_CHARSET; Label9.Font.Charset := DEFAULT_CHARSET; ComboBox1.Font.Charset := DEFAULT_CHARSET; GroupBox1.Font.Charset := DEFAULT_CHARSET; GroupBox2.Font.Charset := DEFAULT_CHARSET; Label3.Font.Charset := DEFAULT_CHARSET; Label4.Font.Charset := DEFAULT_CHARSET; //? UseLanguage('de_DE'); ReTranslateComponent(Self); English1.Enabled:=True; German1.Enabled:=False; Russian1.Enabled:=True; if ComboBox1.ItemIndex=-1 then ComboBox1.ItemIndex:=ComboIndex; end else if Language='Russian' then begin //Form1 AutoUpgrader1.InfoFileURL:='http://xxx/update/autoupgrade_ru.cgi'; Font.Charset := RUSSIAN_CHARSET; Label2.Font.Charset := RUSSIAN_CHARSET; Label10.Font.Charset := RUSSIAN_CHARSET; GroupBox1.Font.Charset := RUSSIAN_CHARSET; Label9.Font.Charset := RUSSIAN_CHARSET; ComboBox1.Font.Charset := RUSSIAN_CHARSET; GroupBox1.Font.Charset := RUSSIAN_CHARSET; GroupBox2.Font.Charset := RUSSIAN_CHARSET; Label3.Font.Charset := RUSSIAN_CHARSET; Label4.Font.Charset := RUSSIAN_CHARSET; //? UseLanguage('ru_RU'); ReTranslateComponent(Self); English1.Enabled:=True; German1.Enabled:=True; Russian1.Enabled:=False; if ComboBox1.ItemIndex=-1 then ComboBox1.ItemIndex:=ComboIndex; end else begin if (GetCurrentLanguage()='EN') then begin //Form1 AutoUpgrader1.InfoFileURL:='http://xxx/update/autoupgrade_en.cgi'; Font.Charset := DEFAULT_CHARSET; Label2.Font.Charset := DEFAULT_CHARSET; Label10.Font.Charset := DEFAULT_CHARSET; GroupBox1.Font.Charset := DEFAULT_CHARSET; Label9.Font.Charset := DEFAULT_CHARSET; ComboBox1.Font.Charset := DEFAULT_CHARSET; GroupBox1.Font.Charset := DEFAULT_CHARSET; GroupBox2.Font.Charset := DEFAULT_CHARSET; Label3.Font.Charset := DEFAULT_CHARSET; Label4.Font.Charset := DEFAULT_CHARSET; //? UseLanguage('EN'); RetranslateComponent(Self); English1.Enabled:=False; German1.Enabled:=True; Russian1.Enabled:=True; if ComboBox1.ItemIndex=-1 then ComboBox1.ItemIndex:=1; Language:='English'; end else if (GetCurrentLanguage()='de_DE') then begin //Form1 AutoUpgrader1.InfoFileURL:='http://xxx/update/autoupgrade_de.cgi'; Font.Charset := DEFAULT_CHARSET; Label2.Font.Charset := DEFAULT_CHARSET; Label10.Font.Charset := DEFAULT_CHARSET; GroupBox1.Font.Charset := DEFAULT_CHARSET; Label9.Font.Charset := DEFAULT_CHARSET; ComboBox1.Font.Charset := DEFAULT_CHARSET; GroupBox1.Font.Charset := DEFAULT_CHARSET; GroupBox2.Font.Charset := DEFAULT_CHARSET; Label3.Font.Charset := DEFAULT_CHARSET; Label4.Font.Charset := DEFAULT_CHARSET; //? UseLanguage('de_DE'); ReTranslateComponent(Self); English1.Enabled:=True; German1.Enabled:=False; Russian1.Enabled:=True; if ComboBox1.ItemIndex=-1 then ComboBox1.ItemIndex:=1; Language:='German'; end else if (GetCurrentLanguage()='ru_RU') then begin //Form1 AutoUpgrader1.InfoFileURL:='http://xxx/update/autoupgrade_ru.cgi'; Font.Charset := RUSSIAN_CHARSET; Label2.Font.Charset := RUSSIAN_CHARSET; Label10.Font.Charset := RUSSIAN_CHARSET; GroupBox1.Font.Charset := RUSSIAN_CHARSET; Label9.Font.Charset := RUSSIAN_CHARSET; ComboBox1.Font.Charset := RUSSIAN_CHARSET; GroupBox1.Font.Charset := RUSSIAN_CHARSET; GroupBox2.Font.Charset := RUSSIAN_CHARSET; Label3.Font.Charset := RUSSIAN_CHARSET; Label4.Font.Charset := RUSSIAN_CHARSET; //? UseLanguage('ru_RU'); ReTranslateComponent(Self); English1.Enabled:=True; German1.Enabled:=True; Russian1.Enabled:=False; if ComboBox1.ItemIndex=-1 then ComboBox1.ItemIndex:=1; Language:='Russian'; end; end; if (Background='Blue') or (Background='') then begin Image3.Picture:=Image23.Picture; Blue1.Checked:=True; Vista1.Checked:=False; Red1.Checked:=False; Black1.Checked:=False; Win71.Checked:=False; Light1.Checked:=False; Blue1.Enabled:=False; Vista1.Enabled:=True; Red1.Enabled:=True; Black1.Enabled:=True; Win71.Enabled:=True; Light1.Enabled:=True; Background:='Blue'; end; if Background='Vista' then begin Image3.Picture:=Image22.Picture; Blue1.Checked:=False; Vista1.Checked:=True; Red1.Checked:=False; Black1.Checked:=False; Win71.Checked:=False; Light1.Checked:=False; Blue1.Enabled:=True; Vista1.Enabled:=False; Red1.Enabled:=True; Black1.Enabled:=True; Win71.Enabled:=True; Light1.Enabled:=True; end; if Background='Red' then begin Image3.Picture:=Image24.Picture; Blue1.Checked:=False; Vista1.Checked:=False; Red1.Checked:=True; Black1.Checked:=False; Win71.Checked:=False; Light1.Checked:=False; Blue1.Enabled:=True; Vista1.Enabled:=True; Red1.Enabled:=False; Black1.Enabled:=True; Win71.Enabled:=True; Light1.Enabled:=True; end; if Background='Black' then begin Image3.Picture:=Image25.Picture; Blue1.Checked:=False; Vista1.Checked:=False; Red1.Checked:=False; Black1.Checked:=True; Win71.Checked:=False; Light1.Checked:=False; Blue1.Enabled:=True; Vista1.Enabled:=True; Red1.Enabled:=True; Black1.Enabled:=False; Win71.Enabled:=True; Light1.Enabled:=True; end; if Background='Win7' then begin Image3.Picture:=Image26.Picture; Blue1.Checked:=False; Vista1.Checked:=False; Red1.Checked:=False; Black1.Checked:=False; Win71.Checked:=True; Light1.Checked:=False; Blue1.Enabled:=True; Vista1.Enabled:=True; Red1.Enabled:=True; Black1.Enabled:=True; Win71.Enabled:=False; Light1.Enabled:=True; end; if Background='Light' then begin Image3.Picture:=Image27.Picture; Blue1.Checked:=False; Vista1.Checked:=False; Red1.Checked:=False; Black1.Checked:=False; Win71.Checked:=False; Light1.Checked:=True; Blue1.Enabled:=True; Vista1.Enabled:=True; Red1.Enabled:=True; Black1.Enabled:=True; Win71.Enabled:=True; Light1.Enabled:=False; end; if Headline<>'' then Label2.Caption:=Headline; end; |
Re: FormShow mit CoolTrayIcon dauert zu lange
Danke Matze,
ich weiß, da gibt es zum jetzigen Zeitpunkt in meinem Programm noch so einige Blöcke etc. die ich schützen muss und will. Aber Du hast aufjedenfall recht. Den Block im OnCreate, habe ich aber soeben geändert. Danke. Gruß Jens |
Alle Zeitangaben in WEZ +1. Es ist jetzt 08:18 Uhr. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024-2025 by Thomas Breitkreuz