Compiler seems to refuse to execute a single line of code (TDateTime related?)

Posted on 2004-10-23
Last Modified: 2010-04-05
This is how my code looks (the second method has been simplified significantly in my attempt to solve this problem myself):

procedure TPrintClippingLabels.PopulateDates(
  ASearchInfo: TKey);
  iI:        integer;
  aDateList: TClippingLabelDateList;
  //  Fill in the dateComboBox with dates corresponding to the chosen media
  aDateList := TConnection.GetInstance.GetClippingLabelDates(ASearchInfo);

  {Make an improvised index of mediaID/Date so the date can be retrieved in
  TDateTime format}
  SetLength(aRegistrations, High(aDateList) + 1);
  for iI := Low(aDateList) to High(aDateList) do begin
    with aRegistrations[iI] do begin
      MediaID := ASearchInfo;
      RegistrationDate := ADateList[iI];

and where my little improvised index is used:

procedure TPrintClippingLabels.UpdateAmount(AMedia: TKey;
  ADate: string);
  iI: integer;
  dTrueDate: TDateTime;
  sDateConversionHolder: string;
  bMediaAlike: boolean;
  bDateAlike: boolean;
  //  Update FUI.lblAmount with the correct amount of labels to be printed

  // Find the TDateTime corresponding to the string retrieved from the GUI
  for iI := Low(aRegistrations) to High(aRegistrations) do

    dTrueDate := aRegistrations[iI].RegistrationDate;



and here are the type definitions of the custom datatypes:

  TClippingLabelInfoList = array of TClippingLabelInfo;
  TKey = type integer;
  TRegistration = record  //  aRegistrations is a unit-wide variable of this type
    MediaID: TKey;
    RegistrationDate: TDateTime;

The idea is that I store list of ID's (integer) and  TDateTimes in aDateList so that, when the date has been presented to the user and he's chosen a single date (it has been passed through the DateTimeToString procedure to make it presentable in a combobox), I can compare the stored values of aDateList (also passed through DateTiemToString) to the text coming from the ComboBox of the GUI and thereby ascertain which TDateTime that corresponds to the text passed from the GUI.

Now my problem is, when I'm stepping through my program the line dTrueDate := aRegistrations[iI].RegistrationDate; is not executed! The compiler seems to just skip the line, no eror message or anything! I've tried everything I could think of at least twice, to no avail and I'm about ready to start breaking stuff!

I hope this is enough of the code for you guys to help me, otherwise just ask and I'll post whatever you need!

By the way I'm using Delphi 5 pro on a windows XP pro machine.

Any help would be greatly appreciated!

Question by:Xenix
    LVL 17

    Accepted Solution

    It is skip because of optimization.
    It is local variable not used anywhere.
    LVL 17

    Expert Comment

    You should either make it global or use in assignment ( as right argument) or as a procedure call argument.

    The same is for example with a procedure which is not called anywhere in the program.
    The code for such a procedure is not generated at all.

    Notice that there is no blue dot on left margin in an editor pane for these lines of code.
    LVL 3

    Author Comment

    Annoying as it is to have spend so much time trying to solve a problem that wasn't REALLY there, you are right!

    As soon as I ignored the problem and continued with my code the problem solved itself, aparently I had no clue as to how the compiler does optimization.
    Not that I would do it when the program is to be compiled finally, but there is an option somewhere in the IDE to switch off optimization, right?
    LVL 3

    Author Comment

    Oh, and by the way, thanks so much for your help!

    You saved both windows and furniture in my apartment :)

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Course: From Zero to Hero with Nodejs & MongoDB

    Interested in Node.js, but don't know where to start or how to learn it properly? Confused about how the MEAN stack pieces of MongoDB, Expressjs, Angularjs, and Nodejs fit together? Or how it's even possible to run JavaScript outside of the browser?

    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…
    This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
    Sending a Secure fax is easy with eFax Corporate ( First, Just open a new email message.  In the To field, type your recipient's fax number You can even send a secure international fax — just include t…
    Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…

    913 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

    13 Experts available now in Live!

    Get 1:1 Help Now