Question

Code not executing unless showmessage or showdialog preceds it!?

Asked by: hibbidiji

I have the following line of code that works:

if not fillform(browser,'username',uname) then showmessage('it just posted');

this doesnt work:

if not fillform(browser,'username',uname) then logger.add('it just posted');

logger is a jedi component log component

This is 100% repeatable.  the code (fillform) simply WILL NOT EXECUTE unless done as in the first instance and thats not acceptable.  please help!

This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.

Subscribe now for full access to Experts Exchange and get

Instant Access to this Solution

  • Plus...
  • 30 Day FREE access, no risk, no obligation
  • Collaborate with the world's top tech experts
  • Unlimited access to our exclusive solution database
  • Never be left without tech help again

Subscribe Now

Asked On
2005-09-10 at 20:00:13ID21557282
Tags

fillform

,

showdialog

,

showmessage

Topic

Delphi Programming

Participating Experts
3
Points
500
Comments
29

Trusted by hundreds of thousands everyday for fast, accurate and reliable tech support.

  • "The time we save is the biggest benefit of Experts Exchange to Warner Bros. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange." Mike Kapnisakis, Warner Bros.
  • "Our team likes having a resource that is more secure than just using Google and most experts using this service really know their stuff. It's nice to look here first versus using Google." Dayna Sellner, Lockheed Martin
  • "Anytime that I've been stumped with a problem, 9 out of 10 times Experts Exchange has either the accepted solution or an open discussion of the potential solution to the problem." Kenny Red, eBay Inc.

See what Experts Exchange can do for you.

Got a question?

We've got the answer.

Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.

Screenshot of Experts Exchange Knowledgebase

Need individual assistance?

Our experts are ready to help.

If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.

Screenshot of Experts Exchange Knowledgebase

Want to learn from the best?

Read articles from industry experts.

Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.

Screenshot of an Article

Working on a long term project?

Store your work and research.

Save solutions to your questions, answers you’ve discovered through searching plus helpful articles in your personal knowledgebase for easy future access.

Screenshot of Experts Exchange Knowledgebase

Access the answers to your technology questions today.

Subscribe Now

30-day free trial. Register in 60 seconds.

What Makes Experts Exchange Unique?

Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Trusted by the world's most respected brands.

image of each brand's logo

Faithfully serving IT professionals since 1996.

Experts Exchange Logo

Try it out and discover for yourself.

Subscribe Now

30-day free trial. Register in 60 seconds.

Related Solutions

  1. Change fonts in ShowMessage / MessageDlg
    I need a way to change the fonts in ShowMessage and MessageDlg functions.
  2. memory leak showmessage??!!
    unit Unit1; interface uses Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls; type TForm1 = class(TForm) Memo1: TMemo; Button1: TButton; Button2: TButton; procedure Button2Click(Sender: TObject); procedure Button1C...
  3. position of the showmessage window...
    Hi guys, is there a way to change the position of the showmessage windows to other place instead of the center of the screen? best regards, Manuel López (lopem)
  4. showmessage
    I am using showmessage to help me develop a program. However, I am now showing a string which is very large... The parts of the string that I want to look at are off the page and I can not get to them? Is there a scrollable version of Showmessage? If not how best can I see th...
  5. showmessage()
    hi i wanna write a message in 2 lines in Showmessage() how can i do that
  6. Difficulty using showmessage in Threads.
    I want to use Showmessage from within a Thread and, when the program arrives to execute the showmessage dialog it gives an Exception Notification with a message “ Canvas does not allow drawing” and stops the process. The showmessage does not appear. I'm using DELPHI 7. on WIN...

Free Tech Articles

  1. WARNING: 5 Reasons why you should NEVER fix a computer for free.
    It is in our nature to love the puzzle. We are obsessed. The lot of us. We love puzzles. We love the challenge. We thrive on finding the answer. We hate disarray. It bothers us deep in our soul. W...
  2. SCCM OSD Basic troubleshooting
    SCCM 2007 OSD is a fantastic way to deploy operating systems, however, like most things SCCM issues can sometimes be difficult to resolve due to the sheer volume of logs to sift through and the dispe...
  3. Migrate Small Business Server 2003 to Exchange 2010 and Windows 2008 R2
    This guide is intended to provide step by step instructions on how to migrate from Small Business Server 2003 to Windows 2008 R2 with Exchange 2010. For this migration to work you will need the fo...
  4. Create a Win7 Gadget
    This article shows you how to create a simple "Gadget" -- a sort of mini-application supported by Windows 7 and Vista. Gadgets can be dropped anywhere on the desktop to provide instant information, ...
  5. Outlook continually prompting for username and password
    There have been a lot of questions recently regarding Outlook prompting for a username and password whilst using Exchange 2007. There are a few reasons why this would happen and I will try to cover t...
  6. Backup Exchange 2010 Information Store using Windows Backup
    There seems to be quite a lot of confusion around the ability to backup Exchange 2010 using the built in Windows Backup feature. This stems from the omission of this feature prior to Exchange 2007 s...

Cloud Class Webinars

  1. Avoiding Bugs in Microsoft Access
    Alison Balter takes and in-depth look at avoiding bugs in Access. In this webinar you will learn about using the immediate window to debug your applications, invoking the debugger, using breakpoints to troubleshoot, stepping through code, setting the next statement to execute, ...
  2. Top 10 Best New Features in Visio 2010
    Scott Helmers gives live demonstrations of the top 10 new features in Visio 2010. This webinar will teach you how to create compelling diagrams by adding shapes to the page with a single click, linking the shapes in a diagram to data in Excel (or SQL Server, or SharePoint), ...
  3. IT Consultant Business Secrets Revealed
    Michael Munger, Experts Exchange tech pro and IT consultant, pulls back the curtain on his very successful businesses and answers question on every IT consultant and business owner should know about. He shares secrets on what he did to solve the 5 most common problems in IT, ...
  4. Disaster Recovery and Business Continuity
    Quest CTO, Mike Billon, gives an overview of the steps involved in building a dunamic disaster recovery plan. Through case studies and an examination of software/hardware tooles for monitoring and testing, you'll gain a better understandin of where you are, where you want ...
  5. Organize Your Visio Diagrams with Containers and Lists
    Scott Helmers uses cross functional flowcharts, wireframe diagrams, data graphic legends and seating charts to teach you: how to ustilize all three new structured diagram components in Visio 2010, the best practices for organizeing shapes in previous version of Visio, how to organize ...
  6. How to Us Objects, Properties, Events and Methods in Microsoft Access
    Alison Dalter gives an in-depbth look at objects, properties, events and methods in Microsoft Access. In this webinar you will learn about using the object browser, referring to objects, working with properties and methods, working with object variables, understanding the ...

Join the Community

Give a Little. Get a Lot.

Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.

Join the Community

Answers

 

by: RadikalQ3Posted on 2005-09-11 at 00:47:43ID: 14858469

Hi!

Are you saying that fillform is executed only with the line that doesnt have the 'logger.add' ?

This is not possible.... the calls are identical...
I think that fillform is executed in both cases in the same manner...

Debug it and set a break point into fillform, or call to the logger into fillform to know this really...

 

by: hibbidijiPosted on 2005-09-11 at 13:36:14ID: 14860334

I know how to set breakpoints but I dont know how this will help - I'm sure its my stupidity.      

I can confirm that the following is true:


fillform(browser,'username',uname); // DOES NOT WORK
if not fillform(browser,'username',uname) then showmessage('it just posted'); // does work and doesnt make any sense in any way whatsoever

Please elaborate on how you suggest I continue.

If it helps: I can also showmodal a form that I have and it works. if i just SHOW it, it will not work.

twilight zone here we come

 

by: DragonSlayerPosted on 2005-09-12 at 00:44:20ID: 14862227

maybe you wanna show us your fillform code?

 

by: hibbidijiPosted on 2005-09-12 at 00:54:18ID: 14862254

Here is the code for fillform

function tform1.FillForm(WebBrowser: TWebBrowser; FieldName: string; Value: string): Boolean;
var
  i, j: Integer;  
  FormItem: Variant;  
begin  
  Result := False;  
  //no form on document
  if WebBrowser.OleObject.Document.all.tags('FORM').Length = 0 then  
  begin
    Exit;
  end;
  //count forms on document  
  for I := 0 to WebBrowser.OleObject.Document.forms.Length - 1 do  
  begin  
    FormItem := WebBrowser.OleObject.Document.forms.Item(I);  
    for j := 0 to FormItem.Length - 1 do  
    begin
      try  
        //when the fieldname is found, try to fill out
        if FormItem.Item(j).Name = FieldName then
        begin  
          FormItem.Item(j).Value := Value;  
          Result := True;
        end;  
      except  
        Exit;  
      end;  
    end;  
  end;
end;

 

by: BigRatPosted on 2005-09-12 at 04:10:33ID: 14862977

Since "all" "... collection includes one element object for each valid HTML tag" then why

 if WebBrowser.OleObject.Document.all.tags('FORM').Length = 0 then  

instead of

 if WebBrowser.OleObject.Document.forms.Length = 0 then

??

 

by: hibbidijiPosted on 2005-09-12 at 12:53:22ID: 14867004

Not my code, and isnt affecting the situation.   I've now tried it both ways and it doesnt work

 

by: hibbidijiPosted on 2005-09-12 at 22:15:29ID: 14869359

Any other suggestions?

 

by: BigRatPosted on 2005-09-13 at 04:24:57ID: 14870605

Well can we start at the very beginning?

The procedure show red dots for the generated code in the Delphi IDE?

We can break on Result:=false?

Do we get a value for ...forms.length? (I'd assign this to a local Integer and break on the assignment).

What do we get for FormItem?

 

by: DragonSlayerPosted on 2005-09-13 at 11:11:39ID: 14874323

Again, try to compile with Optimisation turned OFF and see if your code executes correctly this time?

 

by: hibbidijiPosted on 2005-09-13 at 12:31:01ID: 14875031

Bigrat,
the problem here is that the fillform code is not even executing.  if i put a logger.add('the fillform proc is working');exit; in the procedure it will not even be executed unless I do the insane showmessage.   I appreciate that this is impossible, but I'm suggesting that there might be some bizarre IDE error

Dragonslayer,
the FIRST thing I did was turn off the optimization, and it is still off.  


Is there something ABOUT showmessage that we can do, that doesnt interrupt or require user input so that I can get this app runnning in the mean time? I've tried a showmodal, then automatically dismissing it but that doesnt work well at all, and of course I realize its a complete bandaid.

 

by: DragonSlayerPosted on 2005-09-13 at 19:53:39ID: 14877727

Let's try to see whether fillform is indeed not called?

Instead of initialising your Result := False in fillform, try a Result := True; and see if you get anything in your log?

 

by: hibbidijiPosted on 2005-09-13 at 22:43:26ID: 14878454

Done, and nothing in the log.  insanity prevails

 

by: DragonSlayerPosted on 2005-09-13 at 23:35:03ID: 14878606

Hmm... then I'm stumped~!

 

by: BigRatPosted on 2005-09-14 at 04:48:35ID: 14879853

If the procedure is shown with red dots on the left then it is compiled and linked into the executable. Therefore one can place a breakpoint on the first statement in the procedure (usually the begin has a dot next to it).

If the break point is NOT invoked then the procedure is NOT being called. Therefore it is necessary to investigate the procedures from which the procedure is called.

So

1. How is the procedure defined (private or is it a message procedure, or virtual or what?)
2. from where and under what circumstances is it being called?

You'll need to post the code I'm afraid. If it is very large I'll accept an E-mail with all due confidentiality of course. It's in my profile.

 

by: hibbidijiPosted on 2005-09-14 at 17:27:21ID: 14885972

I'm under an NDA for function right now.   I cant send the full code.    I have made a number of changes and can identify a few more symptoms at least:

function tform1.FillForm(WebBrowser: TWebBrowser; FieldName: string; Value: string): Boolean;
var
  i, j: Integer;  
  FormItem: Variant;
begin
logger.add('got inside fillform with '+ value+' '+fieldname );// always shown regardless of showmessage or not showing message**********
   result :=TRUE;
  //no form on document
  if WebBrowser.OleObject.Document.forms.Length = 0 then
  begin
  logger.add('exiting because there are no forms on the page');//never shown up in a log because the preceding if is never satisfied**********
    Exit;
  end;
 logger.add('about to count forms');
  //count forms on document  
  for I := 0 to WebBrowser.OleObject.Document.forms.Length - 1 do  
  begin
  logger.add('on iteration'+inttostr(I));// even though the form I am filling is item 1, this only ever iterates to 0 unless the showmessage is there**********
    FormItem := WebBrowser.OleObject.Document.forms.Item(I);  
    for j := 0 to FormItem.Length - 1 do
    begin
      try
        //when the fieldname is found, try to fill out
        if FormItem.Item(j).Name = FieldName then
        begin
        logger.add('*** about to set value of '+inttostr(j)+'item with '+value);// not executed unless the if / showmessage is there**********
          FormItem.Item(j).Value := Value;  
          Result := True;
        end;
      except  
        Exit;  
      end;  
    end;  
  end;
end;


Any ideas?    When I change the first Result to = TRUE, I have to change my IF to make the code execute. in other words:
if fillform(browser,'f_comments',comment)then showmessage('damn it');

whereas when I set it to FALSE by default I need to reverse this to:
if NOT fillform(browser,'f_comments',comment)then showmessage('crap');

Here is my declaration:
function FillForm(WebBrowser: TWebBrowser; FieldName: string; Value: string): Boolean;

thanks for helping guys!

 

by: DragonSlayerPosted on 2005-09-14 at 18:40:43ID: 14886270

perhaps an exception was thrown the first round thru, and the procedure exited?

Try instead:

try
  if FormItem.Item(j).Name = ...
except
  on E: Exception do
  begin
    logger.add('Exception occured due to: ' + E.message + ' ... exiting!');
    Exit;
  end;
end;

That way, you can see clearer the cause of the problem.



DragonSlayer.

 

by: hibbidijiPosted on 2005-09-14 at 20:27:51ID: 14886609

I'M GOING INSANE

This is all physically impossible!

Please look below to see a bit of code that makes it ALL WORK
look for the ****************************
basically just showing what iteration I'm on within the form will make it work.   this just cant be possible!

function tform1.FillForm(WebBrowser: TWebBrowser; FieldName: string; Value: string): Boolean;
var
  i, j: Integer;  
  FormItem: Variant;
begin
logger.add('got inside fillform with '+ value+' '+fieldname );
   result :=TRUE;
  //no form on document
  if WebBrowser.OleObject.Document.forms.Length = 0 then
  begin
  logger.add('exiting because there are no forms on the page');
    Exit;
  end;
 logger.add('about to count forms');
  //count forms on document  
  for I := 0 to WebBrowser.OleObject.Document.forms.Length - 1 do  
  begin
  logger.add('on iteration'+inttostr(I));
    FormItem := WebBrowser.OleObject.Document.forms.Item(I);  
    for j := 0 to FormItem.Length - 1 do
    begin
showmessage(inttostr(j));// THIS MAKES IT WORK. it shows messages for 1,2,3 then it WORKS.**********************************************
      try
        //when the fieldname is found, try to fill out
        if FormItem.Item(j).Name = FieldName then
        begin
        logger.add('*** about to set value of '+inttostr(j)+'item with '+value);
          FormItem.Item(j).Value := Value;  
          Result := True;
        end;
      except  
        Exit;  
      end;  
    end;  
  end;
end;

 

by: DragonSlayerPosted on 2005-09-14 at 20:45:57ID: 14886657

as in the previous posting (from another Q), just create some useless calculation that forces j to be reevaluated/used and see if it works? (remember to turn Optimisation off)

var
  s: Integer;
...
  for j := 0 to FormItem.Length - 1 do
  begin
    s := j + 1;



DragonSlayer.

 

by: hibbidijiPosted on 2005-09-14 at 20:54:38ID: 14886673

I'm getting to the point where I'll just deal with the messages if I have to.   is there a way to programatically check for the existance of a showmessage box and dismiss it?

 

by: hibbidijiPosted on 2005-09-14 at 20:58:42ID: 14886681

cross post there.   I added your code again to no avail.   no change

 

by: hibbidijiPosted on 2005-09-14 at 21:29:20ID: 14886772

I have just compiled this in delphi 7 (I've been using 2005) and its just as bad there.   identical

to clarify my insanity:

this does NOT fill the form:
if not fillform(browser,'f_comments',comment) then form1.Caption :='NOT WORKING';

this DOES fill the form:
if not fillform(browser,'f_comments',comment) then showmessage('NOT WORKING');

Does anyone have ANY reasonable explaination for this?

 

by: DragonSlayerPosted on 2005-09-14 at 21:32:06ID: 14886779

I have nothing more to add to this >_<

 

by: hibbidijiPosted on 2005-09-14 at 22:34:32ID: 14886930

A shame.  thanks for your attempt regardless.  I think it might be gremlins.

 

by: hibbidijiPosted on 2005-09-14 at 23:01:11ID: 14887008

I have taken a change in course.   here is my answer

http://thecoadletter.com/article/0,1410,26531,00.html

I am using that.  

I do need one thing.  I need the value of a hidden field in one of my previously loaded pages in order to post directly to it. the field is called "sect"   Anyone that can give me a nice function that will grab the value of this hidden field gets my points.  I hope everyone hasnt left alread.

 

by: BigRatPosted on 2005-09-15 at 04:17:21ID: 14888228

>>Does anyone have ANY reasonable explaination for this?

Yes, the ShowMessage stops the GUI thread allowing fields to be displayed. The other method simply sets a field which then may ort may not be displayed since it *might* be overwritten later.

What you have not done here is to tell us HOW you establish that something doesn't work.

As far as extracting the hidden field value, I see no other alternative than the way you have done it so far - namely navigating through the document. So getting this to work will solve all problems.

 

by: hibbidijiPosted on 2005-09-15 at 13:13:49ID: 14893033

Bigrat,
Can you think of any other way of stopping the GUI thread?   perhaps I can do it right before my code.  i'm not a great programmer obviously and I dont fully understand what you're getting at

 

by: BigRatPosted on 2005-09-16 at 02:32:23ID: 14896596

What I am getting at is that if you are looking at the screen to establish whether an action has been performed and do not see its results, it does not mean that the action has not been performed. It may have been performed and the screen may have been subsequently overwritten. A similar situation can occur with log files. Namely one operns the file, writes something into it and closes it. I cannot remember how often I do this and find nothing in the file since it was reopened elsewhere and emptied!

The point about the ShowMessage is that it stops the program there and then allowing you to look at the screen or log or whatever. You see the action complete, but removing it shows otherwise. Naturally it may be possible that you have found a bug - that is notz totally excluded - but it is unlikely if code has been produced and if the breakpoint occurs. I listed some points eariler to which you have not responded. One must eleiminate all that is possible before one goes on to investigate the less likely.

 

by: hibbidijiPosted on 2005-09-17 at 02:06:58ID: 14903341

Bigrat,
In executing your above recommendations in testing I have verified that the code inside only actually completes execution to the required point when my if-Not code is implemented.   the log does not show anything, the form is not posting, nothing is working unless I do it like that.   I've given up.   I will grant points to anyone who posts my own code solution code back at me.

 

by: hibbidijiPosted on 2006-03-10 at 18:37:53ID: 16160874

I am requesting that this question be closed.

20120131-EE-VQP-002

3 Ways to Join

30-Day Free Trial

The Experts

98% positive feedback on 31,087 answers since March 2000. angeliii is a Microsoft Most Valuable Professional for his work with MS SQL Server & Develoment.

He has also proven his knowledge of Visual Basic Programming, PHP Scripting and Oracle Databases.

The Experts

97% positive feedback on 10,752 answers since July 2000. lrmoore has more than 18 years experience in the networking industry.

The six-time Mircosoft MVPs specialties include firewalls, virtual private networking, and network management.

Testimonials

"...and excellent source for support... Kind of like having your very own IT dept." Electriciansnet

Testimonials

"I was apprehensive at signing up at first. However... it has already made my life as an IT administrator much easier." JaCrews

Testimonials

"WOW! You guys have great, active, and knowledgeable people on here." moore50

Business Clients

Business Clients

In the Press

"If you’ve got a question... Experts Exchange can supply an answer.”

In the Press

"...an invaluable aid for both IT professionals and those who require tech support."

In the Press

"where IT professionals provide quick answers on just about any topic"

Business Account Plans

Loading Advertisement...