Re: Clean up after you!

From: Ekkehard Domning (edo_at_domis.de)
Date: 08/29/04


Date: Sun, 29 Aug 2004 22:24:36 +0200

Hello,
I am not sure that I have understood well, but the general answer is
- if You have not create an instance you have not to free the instance.
I assume that You have dropped the OpenDialog1 from Your example on Your form.
In this case the form has to free on the destruction of the form itself.
I am a bit confused about Your 'LoadGrid' procedure
- if the procedure need a Filename as a parameter, why did you make this
AssignFile call prior the procedure call. Where become the 'myfile' opened so
that You close it on the finally section?
The cleanest way is to pass the filename and leave the procedure open and
close
the file as needed by itself.

BTW try to avoid this AssignFile stuff and use the TFileStream Component
instead.
Another nice feature is the ReadFromFile function from a TStringList itself.
Assuming that You have Your data organized in a way that
<day>:<month>:<year>=<content>
represent data of one day, You can store all data in one stringlist and access
the data
with the Names, Value properties of the stringlist
e.g.
cells[x.y] :=
LoadedStringList.Values[IntToStr(Day)+':'+IntToStr(Month)+':'+IntToStr(Year)];
assuming the stringlist contains one string
'30:8:2004=Look at Newsgroup'
and the variables Day, Month and Year containing 30,8,2004 the cell will
filled with 'look at Newsgroup'

Best regards
Ekkehard

Geir Baardsen schrieb:
>
> Hi!
> Can anybody tell me if I'm doing the following in a wrong way?
>
> What I do is have a textfile loaded into a stringgrid by the help
> of an OpenDialog
> (it works fine, but am I cleaning up after me?,
> Do I need to free the OpenDialog1?):
>
> procedure TfrmTimeList.btnOpenFileClick(Sender: TObject);
> var
> MyFile : TextFile;
> begin
> try
> if OpenDialog1.Execute then
> begin
> AssignFile(MyFile, OpenDialog1.FileName);
> try
> LoadGrid(grTimeList,OpenDialog1.FileName);
> with grTimeList do
> begin
> FixedColor := clBtnFace;
> EditorMode := false;
> ColCount := 5;
> RowCount := 32;
> ColWidths[1] := 200;
> ColWidths[2] := 50;
> ColWidths[3] := 200;
> ColWidths[4] := 50;
> end;
> except
> on E:EInOutError do
> ShowMessage(E.Message);
> end;
> end;
> finally
> CloseFile(MyFile);
> end;
> end;
>
> :-)

-- 
DomIS Integrated Services - Anette Domning M.A.
	Technische Beratung
Vogelweide 19 - 31137 Hildesheim - Tel.: 05121-6971605
Mail: edo@domis.de Internet: http://www.domis.de


Relevant Pages

  • Re: Outlook Express question
    ... IMproper string. ... Post replies to the newsgroup. ... @="Microsoft Outlook Express 6" ... >>> Jim Carlock ...
    (microsoft.public.windowsxp.general)
  • Re: Outlook Express question
    ... IMproper string. ... Post replies to the newsgroup. ... @="Microsoft Outlook Express 6" ... >>> Jim Carlock ...
    (microsoft.public.windows.inetexplorer.ie6_outlookexpress)
  • RE: All FAX printers are Inaccessible
    ... Check for the string values listed on the right pane. ... This newsgroup only focuses on SBS technical issues. ... you may want to contact Microsoft CSS directly. ... I logged in as the domain admin on the client PC, ...
    (microsoft.public.windows.server.sbs)
  • Re: best design for parse
    ... before I got it accepted that the used VB.net language in ASPNET was ... of this newsgroup. ... the objective to standardize the date string to yyyy-mm-dd ... what is the best way to come up a relevant regex for the incoming ...
    (microsoft.public.dotnet.languages.vb)
  • Re: "save as" and "open" do not respond in MS Word
    ... This message is posted to a newsgroup. ... but enter can be the string or just the enter key. ... Explorer or the Windows shell after you install security update ... even after waiting for 6 to 7 mins. ...
    (microsoft.public.word.docmanagement)