I want to upgrade a former application made in Delphi 7 to Delphi 2010 but I'm experiencing an issue with the chars and strings. After compiling the code, I get a nasty string in the listbox and I'm not aware of the unicode changes brought to D2010. It lists some text like some kind of squres and question marks instead of this: "USB-4761 BoardID=15", altough the following code is working perfectly in Delphi7. What do I need to modify in the bottom code so that text will be displayed correctly in the listbox? {code} procedure TFrmAdvantech.Button1Click(Sender: TObject); var MaxEntries, OutEntries: Smallint; NumOfDevice: Smallint; i, ii: Integer; tempStr: String; ////////////////////////////////////// maybe the trouble string testRes: boolean; begin bRun := False; { Add type of PC Laboratory Card } ErrCde := DRV_DeviceGetList(DeviceList[0], MaxEntries, OutEntries); If (ErrCde <> 0) Then begin DRV_GetErrorMessage(ErrCde, pszErrMsg); Response := Application.MessageBox(pszErrMsg, 'Error!!', MB_OK); Exit; end; { Here NumOfDevice = OutEntries } ErrCde := DRV_DeviceGetNumOfList(MaxEntries); If (ErrCde <> 0) Then begin DRV_GetErrorMessage(ErrCde, pszErrMsg); Response := Application.MessageBox(pszErrMsg, 'Error!!', MB_OK); Exit; end; /////////////////////////////////// Down here comes the problem ///////////////////////////////////////////////////// For i := 0 To (MaxEntries - 1) do begin tempStr := ''; For ii := 0 To MaxDevNameLen do tempStr := tempStr + DeviceList[i].szDeviceName[ii]; ///// DeviceList[i].szDeviceName[ii] is of type char lstDevice.Items.Add(tempStr); end; end; {code}
![]() |
0 |
![]() |
Hodor Ovidiu wrote: > I want to upgrade a former application made in Delphi 7 to Delphi > 2010 but I'm experiencing an issue with the chars and strings. After > compiling the code, I get a nasty string in the listbox and I'm not > aware of the unicode changes brought to D2010. It lists some text > like some kind of squres and question marks instead of this: > "USB-4761 BoardID=15", altough the following code is working > perfectly in Delphi7. What do I need to modify in the bottom code so > that text will be displayed correctly in the listbox? > > {code} > ... > /////////////////////////////////// Down here comes the problem > ///////////////////////////////////////////////////// For i := 0 To > (MaxEntries - 1) do begin > tempStr := ''; > For ii := 0 To MaxDevNameLen do > tempStr := tempStr + DeviceList[i].szDeviceName[ii]; ///// > DeviceList[i].szDeviceName[ii] is of type char > lstDevice.Items.Add(tempStr); end; > end; > {code} Do you have the sourcecode for the DeviceList.szDeviceName ? It may be that you need to replace any strings / chars in that object with AnsiString / AnsiChar. -- Bgds, Lars F. http://Lars.Fosdal.com - There are no stupid questions http://delphi.fosdal.com - Delphi Programming
![]() |
0 |
![]() |
On 22.09.2010 14:49, Hodor Ovidiu wrote: > I want to upgrade a former application made in Delphi 7 to Delphi 2010 but I'm experiencing an issue with the chars and strings. > After compiling the code, I get a nasty string in the listbox and I'm not aware of the unicode changes brought to D2010. It lists some text like some kind of squres and question marks instead of this: "USB-4761 BoardID=15", altough the following code is working perfectly in Delphi7. What do I need to modify in the bottom code so that text will be displayed correctly in the listbox? > > {code} > .... > /////////////////////////////////// Down here comes the problem ///////////////////////////////////////////////////// > For i := 0 To (MaxEntries - 1) do > begin > tempStr := ''; > For ii := 0 To MaxDevNameLen do > tempStr := tempStr + DeviceList[i].szDeviceName[ii]; ///// DeviceList[i].szDeviceName[ii] is of type char > lstDevice.Items.Add(tempStr); > end; > end; > {code} It would be better if you shown a declaration of DeviceList. I suppose szDeviceName is declared in your code as: szDeviceName:array [0..MaxDevNameLen] of char; Simply change its declaration to AnsiChar or TAnsiChar whatever. Don't forget about making tempStr:AnsiString.
![]() |
0 |
![]() |
> {quote:title=Lars Fosdal wrote:}{quote} > Do you have the sourcecode for the DeviceList.szDeviceName ? > It may be that you need to replace any strings / chars in that object > with AnsiString / AnsiChar. Yes I have the source and I've replaced {code} szDeviceName : array [0..49] of char; {code} with {code} szDeviceName : array [0..49] of AnsiChar; {code} It worked perfectly. Thank you!
![]() |
0 |
![]() |
*@Andrew Fionik :* Thank you too, I've solved the problem.
![]() |
0 |
![]() |