[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 274
  • Last Modified:

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

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);
var
  iI:        integer;
  aDateList: TClippingLabelDateList;
begin
  //  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
    FUI.PopulateDates(aDateList[iI]);
    with aRegistrations[iI] do begin
      MediaID := ASearchInfo;
      RegistrationDate := ADateList[iI];
    end;
  end;
end;

and where my little improvised index is used:

procedure TPrintClippingLabels.UpdateAmount(AMedia: TKey;
  ADate: string);
var
  iI: integer;
  dTrueDate: TDateTime;
  sDateConversionHolder: string;
  bMediaAlike: boolean;
  bDateAlike: boolean;
begin
  //  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
  begin
    DateTimeToString(sDateConversionHolder,'c',aRegistrations[iI].RegistrationDate);

    dTrueDate := aRegistrations[iI].RegistrationDate;

  end;
end;

end.

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;
  end;

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!

0
Xenix
Asked:
Xenix
  • 2
  • 2
1 Solution
 
mokuleCommented:
It is skip because of optimization.
It is local variable not used anywhere.
0
 
mokuleCommented:
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.
0
 
XenixAuthor Commented:
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?
0
 
XenixAuthor Commented:
Oh, and by the way, thanks so much for your help!

You saved both windows and furniture in my apartment :)
0

Featured Post

Take Control of Web Hosting For Your Clients

As a web developer or IT admin, successfully managing multiple client accounts can be challenging. In this webinar we will look at the tools provided by Media Temple and Plesk to make managing your clients’ hosting easier.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now