Hello everyone,
I use Delphi 2010 and I'm connecting to MS SQL Server 2008.
My UniDataSource1.DataSet.Refresh breaks in one case, I put the code here (small project)
http://www.filedropper.com/servertest
When you try to compile it - it will lead you to the error line.
I would be happy if someone can explain me why it breaks and what to do to solve it.
Thanks
DataSet Refresh Breaks
-
AndreyZ
Re: DataSet Refresh Breaks
Hello,
In your example, you are working with memory incorrectly, which leads to erasing memory that you did not allocate. To avoid the problem, you should rewrite your GetDateTimePickerText function as follows:
In your example, you are working with memory incorrectly, which leads to erasing memory that you did not allocate. To avoid the problem, you should rewrite your GetDateTimePickerText function as follows:
Code: Select all
function GetDateTimePickerText(const DateTimePicker : TDateTimePicker) : String;
// http://docwiki.embarcadero.com/CodeExamples/XE3/en/GetTextBuf_%28Delphi%29
var SizeInt : Integer;
BufferPWideChar : PWideChar;
begin
SizeInt := DateTimePicker.GetTextLen(); {Get length of string in DateTimePicker}
Inc(SizeInt); {Add room for null character}
SizeInt := SizeInt * SizeOf(Char); // THIS code is added
GetMem(BufferPWideChar, SizeInt); {Creates Buffer dynamic variable}
DateTimePicker.GetTextBuf(BufferPWideChar,SizeInt); {Puts DateTimePicker.Text into Buffer}
Result := StrPas(BufferPWideChar); {Converts Buffer to a Pascal-style string}
FreeMem(BufferPWideChar, SizeInt); {Frees memory allocated to Buffer}
end;Re: DataSet Refresh Breaks
Exactly !
I picked the code, tried to adjust it, but I don't understand those memory stuff
Thanks a lot !
I picked the code, tried to adjust it, but I don't understand those memory stuff
Thanks a lot !
-
AndreyZ
Re: DataSet Refresh Breaks
You are welcome. If any other questions come up, please contact us.