0

I am having an issue where closing and reopening the file in the IDE will change parameters (tparam) for my dataset from integer to shortint. If i change them to integer it appears to save, but once lcosed and reopened it is back as shortint. is there a way around Delphi changing parameters from Integer to Shortint?

I found a similar issue here http://www.delphigroups.info/2/1/284088.html

It appears a bug, but there is there a workaround of some fashion? Upgraded Delphi version is not something I can do at this moment. (reproduction steps outlined in second edit)

EDIT:

This is happening by just placing a TQUERY on the form putting an sql statement in it with a parameter, if you change the value type to integer. save and reopen the value type is then shortint.

EDIT again:

In Delphi 7, create new application. Drop a TQUery on the form. Edit the SQL script to something like 'select * from table where id = :idnumber. Edit the params next. Select idnumber and change VALUE.TYPE to Integer. At this point you can save the file and close. When you reopen the file. And go to params again selecting idnumber it will remain a type ftInteger but the value.type will be Shortint. This is the piece I wish to remain an integer, but unfortunately is getting converted to a shortint.

11
  • What is the underlying database type (Paradox, ADO, etc.) and field type? Commented Sep 13, 2012 at 17:56
  • The TQuery has to be connecting to a database somewhere. If it's an actual TQuery, that's attached to a BDE database of some sort (as I said, Paradox or something else through BDELinks). It could be related to the database driver or the underlying DB column data type, which is why I asked (and will again): What is the underlying database type and field type? (If the DB column is shortint, there's no need to save a parameter pointing to it as an integer, because the column can't hold more than a shortint value.) Commented Sep 13, 2012 at 18:20
  • And I will also say again. there is no database associated with the TQuery component. All you have to do is drop a tquery on a form, add an sql statement with a parameter, assign the parameter value.type to integer and hit save. When you reopen the form it will say "shortint" instead. There is no database associated with the tquery just a component on a form. Commented Sep 13, 2012 at 18:34
  • I just tried exactly that: I created a new D7 app, dropped a TQuery on it, clicked the SQL button in the Object Inspector, typed in SELECT ID FROM sometable WHERE ID = :id, and closed the SQL edit window. Inspecting the form as text, I get one parameter declared (ID), with a DataType = ftUnknown and a ParamType = ptUnknown, neither of which are integer, and therefore aren't saved as integer. Commented Sep 13, 2012 at 18:45
  • if you first change the parameter to value.type of Integer (which auto changes the datatype to ftInteger) and save it, then close the form/pas file, then reopen, it will now be ftInteger with value.type of shortint. (at least in my environment). The database will eventually matter but the issue is occurring either way, as to appear to be a bug in Tquery component or tdataset or something else. This will eventually be on a Firebird database, but again that part isnt needed to create the issue. it appears to occur with only the tquery component itself. Commented Sep 13, 2012 at 19:53

2 Answers 2

7

I can explain the behavior you're seeing, and it's not a bug. (Your question is misleading, BTW. Your actual question, based on the edits and comments, is "Delphi 7 changing Parameter.Value.Type from integer to shortint", which is not the same thing at all.)

You're inspecting the Value.Type of the Param.Value, which is not stored in the .dfm file. Value.Type is set either when the form is streamed in from the dfm and the Value is read, or when Value is set at runtime.

I can demonstrate this by following your steps exactly:

Drop a TQuery on a new blank form. Add some SQL to the TQuery.SQL. I used SELECT Id FROM SomeTable WHERE Id = :id.

Click on the ... for the TQuery.Params, and then the id parameter when the Parameter Editor dialog appears. Click the Value in the Object Inspector, and change the Value.Type to Integer.

Save the project and form, and close them. Reopen the project, right-click on the form, and choose View as Text from the context menu. You'll see the following for the Query1 component:

object Query1: TQuery
  SQL.Strings = (
    'select id from sometable where id = :id')
  Left = 152
  Top = 80
  ParamData = <
    item
      DataType = ftInteger
      Name = 'id'
      ParamType = ptInput
      Value = 0
    end>
end

Note that in the ParamData, there is no Value.Type; that's because it's set when the Value is read, not stored when the form is saved.

Now right-click again, and choose View as Form. Go back to the Query1.Parameters, edit the Value, and set it to a high number (I used 123456789).

Save the form, and then View as Text again. Note the Query1 information:

object Query1: TQuery
  SQL.Strings = (
    'select id from sometable where id = :id')
  Left = 152
  Top = 80
  ParamData = <
    item
      DataType = ftInteger
      Name = 'id'
      ParamType = ptInput
      Value = '123456789'
    end>
end

Note that there is still no stored Value.Type. Check the Object Inspector for the ValueType, and it now says String, even though the Parameter.DataType is still ftInteger. This is caused by the IDE's streaming mechanism seeing the quotes, and setting the Value.Type accordingly.

Again, it has no impact on your running application. The Value.Type in the IDE doesn't matter.

Interesting side note: After seeing the Value.Type as String as mentioned above, if you view the form as text again, remove the ' characters around the Value property, and View as Form, then check the Value.Type of the parameter again, it becomes Integer. This is a further indication that it's set during the streaming process, and at design-time has no meaning.

Sign up to request clarification or add additional context in comments.

1 Comment

Perfect, thanks very much. This was discovered when tracking down a bug related to parameters of a query being of the wrong type. So this must not have been the cause and was not an issue. The explanation is appreciated nonetheless.
0

If you are looking for a simple way to convert the type of variables that have the same image (byte count) use the absolute keyword:

function wordToSmallInt(w : word) : smallInt; inline;
   {$WARN UNSAFE_CODE OFF}
   s : smallInt absolute w;
   {$WARN UNSAFE_CODE ON}
begin
   result := s;
end;

This, of course, works similarly with all data types that have the same size.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.