[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

case no longer works in D2009

Posted on 2009-04-20
22
Medium Priority
?
333 Views
Last Modified: 2013-11-23
in D2009 the debugger doesn't go in the line for the string
procedure AddLog(Value: Variant);
var Msg: string;
begin
  case VarType(Value) of
    varInteger: Msg := VarToStr(Value);
    varString: Msg := VarToStr(Value);
    varDate: Msg := FormatDateTime('dd/mm/yyyy hh:nn:ss', VarToDateTime(Value));
  else
    Msg := 'invalid value';
  end;
  ShowMessage(Msg);
end;
 
procedure TForm1.Button1Click(Sender: TObject);
var V: string;
  D: TDateTime;
  N: Integer;
begin
  V := 'Test';
  AddLog(V);
  D := EncodeDateTime(2009, 04, 20, 12, 00, 00, 00);
  AddLog(D);
  N := 20;
  AddLog(N);
end;

Open in new window

0
Comment
Question by:Geert Gruwez
  • 11
  • 9
  • 2
22 Comments
 
LVL 19

Expert Comment

by:MerijnB
ID: 24183044
It doesn't enter AddLog() at all?
0
 
LVL 38

Author Comment

by:Geert Gruwez
ID: 24183083
no,
it enters the addlog,
but it shows 'invalid value' value for any string passed to the routine
in D7, D2005, D2006, D2007 this works but in D2009 -> invalid value
0
 
LVL 19

Expert Comment

by:MerijnB
ID: 24183088
what does VarType(Value) return?
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 38

Author Comment

by:Geert Gruwez
ID: 24183095
haven't checked that yet ...
0
 
LVL 19

Accepted Solution

by:
MerijnB earned 2000 total points
ID: 24183122
I think it's quite possible it returns another (new) constant which indicates unicode data...
0
 
LVL 12

Expert Comment

by:Hypo
ID: 24183240
It works fine for me when I try your code in a new project in Delphi 2009 - Update 1... maybe you have implemented a unit that affects the VarType function, or has some strange compiler setting set? Have you applied update 1 to your product?

regards
Hypo
0
 
LVL 38

Author Comment

by:Geert Gruwez
ID: 24183267
owkay,
VarType(Value) returs 258 which is a brand spanking new type = varUString

so had to change it to:
varString,varUString: Msg := VarToStr(Value);

now to go all over the code to change that ...

procedure AddLog(Value: Variant);
var Msg: string;
begin
  case VarType(Value) of
    varInteger: Msg := VarToStr(Value);
    varString, varUString: Msg := VarToStr(Value);
    varDate: Msg := FormatDateTime('dd/mm/yyyy hh:nn:ss', VarToDateTime(Value));
  else
    Msg := 'invalid value';
  end;
  ShowMessage(Msg);
end;
 
procedure TForm1.Button1Click(Sender: TObject);
var V: string;
  D: TDateTime;
  N: Integer;
begin
  V := 'Test';
  AddLog(V);
  D := EncodeDateTime(2009, 04, 20, 12, 00, 00, 00);
  AddLog(D);
  N := 20;
  AddLog(N);
end;

Open in new window

0
 
LVL 38

Author Comment

by:Geert Gruwez
ID: 24183272
Hypo,
i guess you didn't see the difference between 'test' and 'invalid value' ?
0
 
LVL 19

Expert Comment

by:MerijnB
ID: 24183278
"now to go all over the code to change that"

I don't understand, is that a problem?
0
 
LVL 38

Author Comment

by:Geert Gruwez
ID: 24183287
it wouldn't be if you would come over and do that for us
only roughly 14million lines of code ...
I'll give you points after, Ok ?
0
 
LVL 19

Expert Comment

by:MerijnB
ID: 24183301
You don't have that many variaties of AddLog() I assume?
0
 
LVL 38

Author Comment

by:Geert Gruwez
ID: 24183321
lol, no, this is just sample code
it's usually in the update procedure for the database tables
every tables has 2 wrappers, 1 with an update statement with a case like this built in
i'm running a search to see how many checks we need to do ...
0
 
LVL 19

Assisted Solution

by:MerijnB
MerijnB earned 2000 total points
ID: 24183330
Can't you do a global search and replace?

replace VarString: with VarString, VarUString:
0
 
LVL 38

Author Comment

by:Geert Gruwez
ID: 24183360
it's narrowed down a bit ... roughly 2500 pieces of code with VarType
0
 
LVL 38

Author Comment

by:Geert Gruwez
ID: 24183372
also
if VarType(Value) = varString

it's not that bad, just will need a lot of testing

thx for the help

0
 
LVL 19

Expert Comment

by:MerijnB
ID: 24183437
It's just one of the pains when moving to a newer Delphi version I guess....
Though having that exact same case so many times in your code feels kinda wrong to me.
0
 
LVL 12

Expert Comment

by:Hypo
ID: 24183654
@Geert_Gruwez:  Damn, I totally missed the point of this question...  Guess I need some stronger coffee over here... :)
0
 
LVL 38

Author Comment

by:Geert Gruwez
ID: 24183669
lol,
they don't like me changing the lowest layers of the code.
so i moved to oracle dba ...

I still have to figure out all the changes for the new Delphi version as i am the most senior delphi
and convert the components, live is nice as dba, but hell in D2009


0
 
LVL 19

Expert Comment

by:MerijnB
ID: 24185347
Since you're in the Benelux, did you get your version via Dr. Bob?
0
 
LVL 38

Author Comment

by:Geert Gruwez
ID: 24191349
version of Delphi ?
nah, i tell manager and manager asked secretary to get a new virgin for him ...

i think directly from Embarcadero
0
 
LVL 38

Author Comment

by:Geert Gruwez
ID: 24191354
Why ? does he get a percentage ?
0
 
LVL 19

Expert Comment

by:MerijnB
ID: 24202761
No, but he wrote some readers specifically on migrating to Delphi 2009 from older versions. It's available for everybody who bought Delphi via him.
0

Featured Post

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Question has a verified solution.

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

Programmer's Notepad is, one of the best free text editing tools available, simply because the developers appear to have second-guessed every weird problem or issue a programmer is likely to run into. One of these problems is selecting and deleti…
Update (December 2011): Since this article was published, the things have changed for good for Android native developers. The Sequoyah Project (http://www.eclipse.org/sequoyah/) automates most of the tasks discussed in this article. You can even fin…
The viewer will learn how to use and create keystrokes in Netbeans IDE 8.0 for Windows.
The viewer will learn how to synchronize PHP projects with a remote server in NetBeans IDE 8.0 for Windows.
Suggested Courses

830 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