Solved

Need some (> quite a lot actually;) help debugging my app

Posted on 2004-03-22
10
284 Views
Last Modified: 2010-04-05
Hi Expertz!!

I'm currently (still) working on my project and although I accomplished about all I wanted to, I would like someone to help me out on debugging the application. I'm pretty convinced that I have not only overlooked certain issues but also used procedures etc. that I could better do without so to speak. A CPU window popping up doesn't tell me one thing at all and a debugger like MemSleuth probably is too sophisticated or option B > I'm too....;)
What I'd like is someone who is willing to take a look and if applicable will comment what goes wrong and where what goes wrong and ofcourse HOW to alter my app without destroying it (that's what I have been doing lately in my attempts to improve the code;)

In contradiction to what I stated earlier I will now post some code fragment which clearly needs rectification or perhaps even a total makeover......he or she who helps me out on this one gets the points.......

This fragment should collect input from some edits and comboboxes which the user edited.....The Re5 is my RichEdit, the Se are SpinEdits and any CB's are comboboxes and other Re's (Re1 etc.) are other RichEdits from which the info should be collected....



//here it goes
with RE5 do
begin
maxLength := 32;
RE5.Clear;
RE5.PerForm(EM_SETMARGINS, EC_LEFTMARGIN or EC_RIGHTMARGIN, MAKELONG(20,20));//set margins

RE5.Lines.add('*******************************************************************************');
RE5.Lines.add('Wachtrapport van de');

if
suiRadiobutton1.checked then      //either radiobutton 1 or 2 will be checked
RE5.lines.add('Vroege Dienst') else //resulting in either option 1
RE5.lines.add('Late Dienst'); //or option 2
RE5.Lines.add('');
RE5.lines.add(DateTimeToStr(Now)); //add time/date string
RE5.Lines.add('*******************************************************************************');
RE5.Lines.Add('Aandachtspunten Planning + Badenreeks:');
RE5.Lines.add('*******************************************************************************');
RE5.SelStart := 0;
RE5.SelLength := 270;
RE5.SelAttributes.Protected := True;
RE5.lines.add(RE1.lines.text);
RE5.Lines.add('');
RE5.lines.add('Gevonden waarden bij analyseren:');
RE5.Lines.add('');
RE5.lines.add('Groffosfaatbad 1 Puntensterkte: '+se1.text+'  Ijzergehalte: '+se3.text);  //and so on
RE5.lines.add('Groffosfaatbad 2 Puntensterkte: '+se2.text+'  Ijzergehalte: '+se4.text);
RE5.lines.add('Ultra Tech       Puntensterkte: '+se5.text);
RE5.Lines.add('*******************************************************************************');
RE5.lines.add('Stand van zaken mbt waterzuivering:');
RE5.Lines.add('*******************************************************************************');
RE5.lines.add('Standreactor:'+cb1.Text);
RE5.lines.add('Indikker:    '+cb2.Text);
if CB5.Text='' then
RE5.lines.add('Grote pers: '+cb3.Text+' is niet in gebruik')
else
RE5.Lines.Add('Grote pers: '+cb3.Text+' staat op: '+CB5.Text);
if CB6.Text='' then
RE5.Lines.Add('Kleine pers: '+cb4.Text+' is niet in gebruik')
else
RE5.lines.add('Kleine pers: '+cb4.Text+' staat op: '+CB6.Text);
RE5.Lines.add('');
RE5.lines.add('Gevonden waarden bij analyseren:');
RE5.Lines.add('');
RE5.Lines.Add('Zink waarde afvalwater:'+se6.text);
RE5.Lines.Add('Tin waarde afvalwater: '+se7.text);
RE5.Lines.add('*******************************************************************************');
RE5.Lines.Add('Ook belangrijk!:');
RE5.Lines.add('*******************************************************************************');
if suicheckbox1.Checked then
RE5.lines.add('Stofzak vervangen:    ja') else
RE5.lines.add('Stofzak vervangen:    nee');
if suicheckbox2.Checked then
RE5.lines.add('Vuilnisbak geleegd:   ja') else
RE5.lines.add('Vuilnisbak geleegd:   nee');
if suicheckbox4.Checked then
RE5.lines.add('Afdekballen overgeschept:   ja') else
RE5.lines.add('Afdekballen overgeschept:   nee');
if suicheckbox5.Checked then
RE5.lines.add('Contactplaatjes gereinigd:   ja') else
RE5.lines.add('Contactplaatjes gereinigd:   nee');
if suicheckbox6.Checked then
RE5.lines.add('Asbakken geleegd:   ja') else
RE5.lines.add('Asbakken geleegd:   nee');
RE5.Lines.Add('*******************************************************************************');
RE5.Lines.add('Algemene aandachtspunten:');
RE5.Lines.add('*******************************************************************************');
RE5.Lines.Add(''+RE2.Lines.text);
//RE5.Lines.add('------------------------------------------------------------------------------------------------');
RE5.Lines.add('*******************************************************************************');
end;
end;

0
Comment
Question by:PeterdeB
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 4
10 Comments
 
LVL 27

Expert Comment

by:kretzschmar
ID: 10647725
?? and what is the problem ??
0
 

Author Comment

by:PeterdeB
ID: 10648032
Hi there,

Well I better not argue with you about whether there is or isn't a problem > so then this piece of code gets discriminated from the potential bunch of problems I have collected;) (btw I was told that using too much richedits and if constructions would result in memory leaks and resource leaks > so my guess was I'd better let someone check this fragment)

Here's the second 'suspect' :

procedure TfrmMain.FormCreate(Sender: TObject);
var
  Image11: TBitmap;
  Image22: TBitmap;
  DLLHandle: THandle;
  a: String;
begin
HMainIcon                := LoadIcon(MainInstance, 'MAINICON');
  Shell_NotifyIcon(NIM_DELETE, @tnid);
  tnid.cbSize              := sizeof(TNotifyIconData);
  tnid.Wnd                 := handle;
  tnid.uID                 := 123;
  tnid.uFlags              := NIF_MESSAGE or NIF_ICON or NIF_TIP;
  tnid.uCallbackMessage    := WM_NOTIFYICON;
  tnid.hIcon               := HMainIcon;
  tnid.szTip               := 'Wachtrapport';
  Shell_NotifyIcon(NIM_ADD, @tnid);
a:= Paramstr(1); //Thanks to Ferrucio for this part!!
if ParamCount > 0 then begin // an associated file has been clicked
  // you are examining the parameters here:
  a := ParamStr(1); // the first parameter must be a filename (your associated text file) that must be opened
  // do more things here like open the file, etc.
  try
  PC.ActivePageIndex:= 3;
    RE5.Lines.LoadFromFile(a);
  except
    ShowMessage('Kan bestand niet laden ' + a);
    Application.Terminate;
  end;
 end else begin
 PC.ActivePageIndex:=0;
 // the app has been started directly without a file as a parameter
  // do something here like open an empty document, etc.
CreateAboutFile := True;
 try if not FileExists('Resource.dll') then
  MessageDlg('De Module ''Resource.dll'' ontbreekt, of is beschadigd. Neem '+#13+#10+'contact op met de auteur om dit probleem te verhelpen. Mail '+#13+#10+'naar: pdbiel@hotmail.com of bel: 06-28434038. Desgewenst '+#13+#10+'kunt u deze module zelf opsporen en in de juiste folder gooien: '+#13+#10+'''C:\Program Files\Wachtrapport''. Bij voorbaat dank! ', mtWarning, [mbOK], 0);
 Exit ;
  DllHandle := LoadLibrary('Resource.dll');
  if DllHandle <> 0 then
  try
    Image11 := TBitmap.Create;
    Image11.Handle := LoadBitMaP(DllHandle, 'BITMAP_1');
    Image11.SaveToFile(PRes+'\BITMAP_1.bmp');
    Image1.Picture.loadfromfile(PRes+'\BITMAP_1.bmp');
    Image11.FreeImage;
    Image22 := TBitmap.Create;
    Image22.Handle := LoadBitmap(DllHandle, 'BITMAP_2');
    Image22.SaveToFile(PRes+'\BITMAP_2.bmp');
    Image2.Picture.LoadFromFile(PRes+'\BITMAP_2.bmp');
    Image22.FreeImage;

  finally
  initializeForm;
    FreeLibrary(DllHandle);
    end;
  except
  on e: Exception do
    Application.HandleException(Sender);
end;
end;
end;


//

My appreciation for checking the first fragment > like I said this is the second part

Regards, Peter
0
 
LVL 5

Accepted Solution

by:
delphized earned 250 total points
ID: 10649726
it looks good, only the

Shell_NotifyIcon(NIM_DELETE, @tnid);

should be in the ondestroy and not in the oncreate; (and when you call it in your code you haven't yet defined the size of the tnid variable!!)
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 

Author Comment

by:PeterdeB
ID: 10656385
Okay Delphized thanks for commenting on this one > I shipped the Shell_NotifyIcon - to the OnDestroy but must admit that I have no idea whatsoever how I should define the size of the tnid variable....perhaps you could shed some more lights please? It would certainly help me a lot........(the points are yours btw > I will post another fragment of code as another question rather than exploiting this one for all the remarks it comes up with)

Thanks in advance......Peter
0
 

Author Comment

by:PeterdeB
ID: 10656411
When I put it in the private section > tnid: TNotifyIconData;
Would that solve my problem?
0
 
LVL 5

Expert Comment

by:delphized
ID: 10657000
I wanted to say that

  Shell_NotifyIcon(NIM_DELETE, @tnid); //here the cbsize member is not defined and the delete is not necessary
  tnid.cbSize              := sizeof(TNotifyIconData); //here you have defined the cbsize member of the tnid record and this id good
  tnid.Wnd                 := handle;
  tnid.uID                 := 123;
  tnid.uFlags              := NIF_MESSAGE or NIF_ICON or NIF_TIP;
  tnid.uCallbackMessage    := WM_NOTIFYICON;
  tnid.hIcon               := HMainIcon;
  tnid.szTip               := 'Wachtrapport';
  Shell_NotifyIcon(NIM_ADD, @tnid); //here you use the tnid that is initialized and this is good

so when you have moved the NIM_DELETE at the end (ondestruction) all goes right because the cbsize is already initialized.

you can declare the tnid where you want, it makes no differences.

hope this is clear, if not, ask me
0
 

Author Comment

by:PeterdeB
ID: 10662525
Hi Delphized! Thanks for you reply again! Just got back from work so that's why it took me so long to respond. I must admit I fail to comprehend to be honest;( Your comments are clear > I now see why the NIM_DELETE had to be moved but the declaration thing just keeps troubling my mind a bit sorry to say. But I'd rather not spoil the evening (and I'm far from 'ready' to just understand all you guys here state, suggest and post > but for myself I already achieved a lot IMHO and that is primarily because of the support I get here at EE from guys like you. For now I dropped this project (just for a couple of days to focus on something else otherwise I start seeing U(ndeclared)FO's whenever I crawl behind my pc;).(There's still one item I cannot clarify > the memory leak of 8 heap blocks but I'll have to be patient since I already spent enough hours finding out where what caused it so......... Which brings me to yet another subject > Another project I'm currently 'working' on involves a win32 service application and it works, without significant problems. What I'd like to do is set the response action after the service drops or fails or terminates > on the second tab of the properties I think. Have you got any idea how to get my hands on those properties and\or do you know whether I have to start digging the Registry (not that that is a problem but I'd rather know for sure before I start tickling xp's registry;) to do so?

Thanks for your patience as well as your support Delphized.....simply priceless..........

Max respect and regards!!

Peter
0
 
LVL 5

Expert Comment

by:delphized
ID: 10665104
when you write a service you have an execute method

(from delphi help)

procedure TService1.Service1Execute(Sender: TService);

begin
  Stream := TMemoryStream.Create;
  try
    ServerSocket1.Port := 80; // WWW port
    ServerSocket1.Active := True;

    while not Terminated do begin //here is the execution

      ServiceThread.ProcessRequests(False);
    end;

    //here the service is finished

    ServerSocket1.Active := False;

  finally
    Stream.Free;
  end;
end;

so when you finish the while not terminated loop you know the service is finished and you can do actions accordingly

bye bye
0
 

Author Comment

by:PeterdeB
ID: 10688543
Hi Delphized > although I thought I had agreed upon receiving responses in my Inbox this is surely not the case. Otherwise I would have responded to your reply a bit earlier ofcourse. Reading all you state raises a huge questionmark right at my desktop so to speak;) After having written a win32 svc app and installing it accordingly I had increased my army of services with 1...well ofcourse;) It hasn't got any functionality yet but that's because I want to prevent myself from rapidly ripping any source code fragment and get compiling without properly knowing what I am doing actually. The service you describe here, what does it do > open a port for whatever or whomever wants to take a look in cyber space and more important > assuming your service operates accordingly, is it common or very useful to have it barging this 'door 80' and right afterwards terminate? Should I think of a service like some feature which is extremely well practiced to do something I can't or couldn't accomplish using common applications?

And regarding my earlier project > when I want to load a template file which already contains text like this:
//beginning text fragment I took from some app which lets you create nfo files

*******************************************************************************
                                     ${1}
*******************************************************************************

-------------------------------------------------------------------------------
                              General Information
-------------------------------------------------------------------------------
Type.................: ${2}
Platform.............: ${3}
Serial #.............: ${5}
More Info............: ${4}
Part Size............: ${14}
Number of Parts......: ${15}
Compression Format...: ${12}
File Validation......: ${13}
Rip or Image.........: ${6}
Image Format.........: ${8}
Image Created with...: ${9}
Burn Tested..........: ${11}
Requires 700 MB CDR..: ${10}
Copy Protection......: ${16}

Title................: ${37}
Artist...............: ${38}
Album................: ${39}
Year.................: ${40}
Genre................: ${41}
Comment..............: ${42}
Type.................: ${43}
Duration.............: ${45}
Number of Songs......: ${46}
Cover(s) Included....: ${44}

//end of text

I'm currently trying to figure out what and how these numbers can be used to preformat the outcome. I have even tried some unnice programs to get my hands on some source code in order for me to understand and decide whether to use edits richedits memos or the like for collecting information the user puts in.......Have you got any idea how these numbers and in particular this layout could serve the purpose of finishing off a nicely formatted document???

In an app I made earlier I use richedits but now I want to know which component to use prior to creating the app....could you shed some light please?

My regards and once again thanks for replying!!

peter
0
 
LVL 5

Expert Comment

by:delphized
ID: 10693646
the example was taken directly from delphi help and was intended only to show you where to put the finalization clause.
A service is used to do a task in the background even when the server is logged off (like batch programs or databases engines...)

About the numbers you write you should explain more (in a new question)

bye :-)
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
Suggested Courses
Course of the Month8 days, 11 hours left to enroll

617 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