Solved

A good Delphi samples site, where?

Posted on 1998-08-25
7
126 Views
Last Modified: 2010-04-04
Hi... where can I find some good delphi examples? for example, When I call a dialog box, then close it.. if I try to call it again, application sends an exception error. I'm freeing the dialog, so.. which may be the problem?

Thanks in advance
Jaime
0
Comment
Question by:skel
  • 2
  • 2
  • 2
  • +1
7 Comments
 
LVL 5

Expert Comment

by:knowlton
ID: 1337693
Can you include a snippet of code showing what you are doing when you make the call?  

I think sometimes you don't need to FREE the dialog, especially when it is being auto-created.
0
 

Author Comment

by:skel
ID: 1337694
There you are the whole method that calles the dialog box:

***************************************************************

Procedure TEmulador.MnuSerialClick(Sender: TObject);
var S1      : string[2];
    S2      : string[7];
    ArchIni : TIniFile;

begin
  with TSetup.Create(Self) do
  ArchIni := TIniFile.Create( 'Monitor.ini' );
  try
    if Setup.ShowModal = 1 then
      begin
        str(Setup.ComPort.ItemIndex+1,S1);
        ArchIni.WriteString( 'Setup', 'Port', S1 );
        str(Setup.m_iBaudRate,S2);
        ArchIni.WriteString( 'Setup', 'BaudRate', S2 );
      end;
  finally
    ArchIni.Free;
    Setup.Free;
  end;
end;

***************************************************************


And these are the methods inside de unit controlling the box:


***************************************************************

procedure TSetup.FormCreate(Sender: TObject);
var S1          : string[2];
    S2          : string[7];
    P,Codigo    : Integer;
    B           : Longint;
    ArchIni     : TIniFile;

begin
  ArchIni := TInifile.Create('Monitor.ini');
  S1 := ArchIni.ReadString('Setup', 'Port', '2');
  val(S1,P,Codigo);
  if Codigo = 0 then
    ComPort.ItemIndex := P-1;
  S2 := ArchIni.ReadString('Setup', 'BaudRate', '19200');
  val(S2,B,Codigo);
  case B of
    110    : BaudRate.ItemIndex := 0;
    300    : BaudRate.ItemIndex := 1;
    600    : BaudRate.ItemIndex := 2;
    1200   : BaudRate.ItemIndex := 3;
    2400   : BaudRate.ItemIndex := 4;
    4800   : BaudRate.ItemIndex := 5;
    9600   : BaudRate.ItemIndex := 6;
    14400  : BaudRate.ItemIndex := 7;
    19200  : BaudRate.ItemIndex := 8;
    38400  : BaudRate.ItemIndex := 9;
    56000  : BaudRate.ItemIndex := 10;
    57600  : BaudRate.ItemIndex := 11;
    115200 : BaudRate.ItemIndex := 12;
  end;
  ArchIni.Free;

end;

procedure TSetup.BaudRateClick(Sender: TObject);
const
    BaudRates: array[ 0..12 ] of Longint =
    ( 110, 300, 600, 1200, 2400, 4800, 9600, 14400, 19200, 38400, 56000, 57600, 115200 );

begin
  if ( Sender is TRadioGroup ) then
    m_iBaudRate := BaudRates[ ( Sender as TRadioGroup ).ItemIndex ]
  else
    m_iBaudRate := -1;
end;

***************************************************************

Any help would be greatly appreciated...

Thanks in advance
Jaime
0
 
LVL 5

Expert Comment

by:knowlton
ID: 1337695
Do you have a way to send me a demo with the source code included?

My e-mail is:  knowltonfamily@yahoo.com

I've had trouble with this in the past (creating dialogs at run-time and then having them crash when I close / open them again) and I know part of the problem has to do with whether Delphi is auto-creating the form or not.  This can be found under the OPTIONS for the Delphi project.  The OPTIONS button is right next to the Add File and Delete File buttons.

Tom
0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
LVL 8

Expert Comment

by:ZifNab
ID: 1337696
Hi skel!

 Look at delphi deli website.

 There is a search feature which connects you to chami's place for delphi examples.

Regards, Zif.
0
 

Author Comment

by:skel
ID: 1337697
If you write the URL of the delphi deli website, I will be very very happy :)
0
 
LVL 3

Accepted Solution

by:
philipleighs earned 50 total points
ID: 1337698
Hi,

The problem is in the first procedure you listed above. After the "with" on the first line, you need a "begin" so that the rest of the procedure is inside the "with". Currently only the next line is enclosed in the "with". Better still, get rid of that nasty "with" and declare a local variable for the dialog called "SetupDialog" or something. Note that "Setup" is a global instance of the dialog.
Also, make sure that TSetup is not autocreated. Go into Project | Options to check.
Also, you should never Free a dialog, you should only ever Release it. Read the help for the reason why.
The code should look like:


Procedure TEmulador.MnuSerialClick(Sender: TObject);
var S1      : string[2];
    S2      : string[7];
    ArchIni : TIniFile;
    SetupDialog: TSetup;
begin
  SetupDialog := TSetup.Create(Application);
  ArchIni := TIniFile.Create( 'Monitor.ini' );
  try
    if SetupDialog.ShowModal = 1 then
      begin
        str(SetupDialog.ComPort.ItemIndex+1,S1);
        ArchIni.WriteString( 'Setup', 'Port', S1 );
        str(SetupDialog.m_iBaudRate,S2);
        ArchIni.WriteString( 'Setup', 'BaudRate', S2 );
      end;
  finally
    ArchIni.Free;
    SetupDialog.Release;
  end;
end;
0
 
LVL 8

Expert Comment

by:ZifNab
ID: 1337699
hi skel, http://delphi.lehner.at/ Zif.
0

Featured Post

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

708 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now