-2

I had a code like this in Delphi 7:

var    
  mValueBuffer : TValueBuffer;
begin
  Double(MValueBuffer) := Date;
end;

When I compile this in Delphi 10 Seattle it fails with an invalid typecast error. I am using the Data.DB unit.

David Heffernan
  • 601,492
  • 42
  • 1,072
  • 1,490
  • *I had a code like that* and *Not sure was a TValueBuffer*? I don't get your question then. What is your actual issue? – Jan Doggen Dec 18 '15 at 14:45
  • 1
    You made the exact same mistake in the question you asked earlier. You did not provide anywhere near enough details. Please show a [mcve]. Unless you do that then this question is off topic here. Please take some time reading the articles in the [help]. – David Heffernan Dec 18 '15 at 14:47
  • Try to comile that !! you have to use Data.db in the uses... – Eric Dumont Dec 18 '15 at 15:30
  • TValueBuffer = TArray; declared in Data.db. so if the code I provide that you can put on a TButton.click and as soon as you compile there is the error..what else should I give you? – Eric Dumont Dec 18 '15 at 15:31
  • 1
    You need to include a **full, compilable** example. And why would you think you can typecast a `TValueBuffer` to a `Double`? They're not anywhere close to the same thing. You can't typecast a car to a banana just because you want a snack. The sample code you provided is nonsense. What is the **actual** problem you're trying to solve, instead of the **senseless code that won't compile**?. – Ken White Dec 18 '15 at 15:45
  • I am migrating a components set from Delphi 7 to Delphi 10. – Eric Dumont Dec 18 '15 at 15:47
  • 1
    Please don't fight us. We know how to do this. Please provide a [mcve]. Please spend some time at the [help]. Please don't make us repeat this message again. – David Heffernan Dec 18 '15 at 15:49

1 Answers1

3

Having extracted the information from your comments, and edited the question to use them, we can now make sense of this question. Please heed the advice given in the comments for future questions.

The type TValueBuffer is declared in Data.DB as a dynamic array of byte. As such, the type cast is invalid. You cannot hope to cast a dynamic array, essentially a pointer, to a double precision floating point value. These types are different sizes. Hence the compiler error. Even if the types were the same size, the cast makes no sense at all.

Why did this compile in Delphi 7. Well, the Delphi 7 standard libraries do not have a type named TValueBuffer. So we can only presume that TValueBuffer is defined in either your code, or libraries that you use. Presumably, your uses of the Data.DB unit hides the TValueBuffer type that was intended to be used. Find that type and you will have the answer to your problem.

David Heffernan
  • 601,492
  • 42
  • 1,072
  • 1,490
  • Thanks I appreciate :) – Eric Dumont Dec 18 '15 at 15:57
  • In Delphi 7 it was a pointer. – Eric Dumont Dec 21 '15 at 10:26
  • If `TValueBuffer` was a pointer in D7, then your code would not compile either. I'm honestly not sure what you want from us here. I cannot see what more I could do given the question that you asked. I'm not sure you fully appreciate how this site works and what we have to offer. – David Heffernan Dec 21 '15 at 10:28
  • I found out how to solve my problem just in case someone else would run in same problemOld version Assigning a Date to a pointer iftDate: Longint(Buffer) := DateTimeToTimeStamp(STOD(RawText)).Date; New Version Converting a Date into a TArray iftDate: TDBBitConverter.From(STOD(RawText), Buffer, 0); – Eric Dumont Dec 21 '15 at 11:21
  • You really have no idea what this site is all about. Only you have your code. Nobody else has it. And we cannot see it. It's not in the question. I answered the question that you asked. If you want a programmer to help with your private code base, hire one. If you want us to answer questions, ask them here. But don't expect to ask a question and then get an answer relating to the code that we cannot see. Do you believe that anyone could have said more than I said in the answer, given the question that you asked? Please try to learn more about how this site works: [help] – David Heffernan Dec 21 '15 at 11:30