TDBEdit component allowing too many characters

sse

Member²
Hi,

I am encountering a problem with dbedits in Delphi XE allowing the user to type four times (4x's) as many characters in an edit box than allowed.

This is for an al32utf8 database with the underlying structure of the table set to CHAR (not BYTE). It's clear the edit box is using the size of the data and not the length.

Is there a way to fix this so that the number of chars is the limit and not the number of bytes?

- BytesPerCharacter is set to bcAutoDetect.
- I have tried toggling NoUnicodeSupport with no luck.

Someone else had a similar post here. And it was indicated that there is a solution, but it's not posted.

Does anyone have any ideas on how to fix this?

 
Last edited:
still waiting... I would be grateful for a response. It has been well over 24 hours.

I changed the subject line since the problem has nothing to do with DBEdits and more to do with character lengths being miscalculated.

Please reply back, thank you.

Shereif
 
Hi, it is me the one who solved the problem ( did also send you an email).

this is the very first modification you have to do to the sources to get what you want (and what the VCL wants as correct behaviour for field.fieldsize):

function TOracleQuery.FieldSize(FieldId: Integer): Integer;
begin
if (FieldId < 0) or (FieldId > FieldList.Count - 1) then
raise Exception.Create('Field ' + IntToStr(FieldId) + ' does not exist');
with FieldList.Items[FieldId] as TFieldData do
if buftype = otString then // only meaningful for strings
Result := CharSize // I return the size of the field measured in number of characters
// result := bufsize - 1; // this was the original implementation
else
Result := 0;
end;

This will make the fields report the correct size expressed in characters, not in bytes.

Anyway this could be only the tip of the iceberg and for the moment I am not able to track down all the modifications I made to the original DOA sources. I have made MANY of them and I also changed the whole internal representation of stringfields in order to make it much less memory hungry.

Since I made this fix after having made all the other modifications I can't tell you which other parts will need to be fixed.

I suggest you to hunt down all the other places inside the DOA sources where TOracleQuery.FieldSize gets called and correct them accordingly in case they are affected by the above fix (which makes TOracleQuery.FieldSize return the number of characters instead of their size in bytes)

Of course if you too did write some code that makes use of TOracleQuery.FieldSize, you need to fix that too.
 
Looking back at my sources I remembered that the fix I posted will break RAW fields, since they have "charsize" = 0, and having TOracleQuery.FieldSize returning "charsize" will make Doa allocate zero-sized buffers.

I had to add this fix to TOracleQuery.InternalDescribe, to have RAW fields work correctly:

// this is needed because otRaw fields are mapped
// to TStringFields, so we need to have charsize set.
otRaw:
begin
buftype := otString;
bufsize := (dbsize * 2) + 1;
charsize := bufsize; //
 
here is another part of the fix:

inside: OracleData.Pas,
in

function TOracleDataset.GetRecBufSize: Integer;

this:
if DataType = ftWideString then ds := Size * 2;

must be changed to this:

if DataType = ftWideString then ds := Size * 4;

since now field.size is in characters and not in bytes...

Well... I told you it wasn't that simple..
 
Back
Top