Recent

Author Topic: win1256 [SOLVED]  (Read 5387 times)

Mhmd60

  • Newbie
  • Posts: 6
win1256 [SOLVED]
« on: June 12, 2014, 08:48:36 am »
I have a problem using lazarus with mssql, my database codepage is windows 1256 when I connect to the database and start using the application I saw this text instead of the Arabic characters '??????????'.
Any help please?
« Last Edit: November 09, 2016, 07:18:52 pm by Mhmd60 »

luca

  • Jr. Member
  • **
  • Posts: 83
Re: win1256
« Reply #1 on: June 12, 2014, 10:29:45 am »
Hi.
Try to use
Code: [Select]
AnsiToUTF8(qry.FieldByName('Fieldname').AsString)

Regards
Luca

mangakissa

  • Hero Member
  • *****
  • Posts: 1131
Re: win1256
« Reply #2 on: June 12, 2014, 11:07:43 am »
I understand the problem of Mhmd60. luca's option is a workaround, but doesn't work with database GUI components.
Lazarus 2.06 (64b) / FPC 3.0.4 / Windows 10
stucked on Delphi 10.3.1

taazz

  • Hero Member
  • *****
  • Posts: 5368
Re: win1256
« Reply #3 on: June 12, 2014, 11:22:35 am »
luca's option is a workaround, but doesn't work with database GUI components.

It doesn't? How is that?
Good judgement is the result of experience … Experience is the result of bad judgement.

OS : Windows 7 64 bit
Laz: Lazarus 1.4.4 FPC 2.6.4 i386-win32-win32/win64

Mhmd60

  • Newbie
  • Posts: 6
Re: win1256
« Reply #4 on: June 12, 2014, 11:34:42 am »
Thank you Mr. Luca and Mr. mangakissa, but as Mr. mangakissa said it doesn't work.

marcov

  • Administrator
  • Hero Member
  • *
  • Posts: 11452
  • FPC developer.
Re: win1256
« Reply #5 on: June 12, 2014, 12:06:09 pm »
What is your windows codepage? The database can be codepage  1256, but that doesn't mean the default windows codepage is.

Mhmd60

  • Newbie
  • Posts: 6
Re: win1256
« Reply #6 on: June 12, 2014, 01:20:50 pm »
Thank you Mr. marcov, my windows codepage is win1256 Arabic.

Mike.Cornflake

  • Hero Member
  • *****
  • Posts: 1260
Re: win1256
« Reply #7 on: June 12, 2014, 01:22:58 pm »
luca's option is a workaround, but doesn't work with database GUI components.

It doesn't? How is that?
I assume you're asking "Why doesn't AnsiToUTF8(qry.FieldByName('Fieldname').AsString) work for the DB aware GUI controls?"
Quick answer - because those controls populate their value directly from the dataset, there's no place that Luca's workaround can be applied.

Well actually, that's not true. Moving away from your question @Taaz

@Mhmd60  Try the following code...

Code: [Select]
...
  TForm1 = Class(TForm)
    Procedure DatasetOnGetText(Sender: TField; Var aText: Ansistring; DisplayText: Boolean);
    Procedure InitialiseDataset;   
..

Procedure TForm1.DatasetOnGetText(Sender: TField; Var aText: Ansistring;
  DisplayText: Boolean);
Begin
  aText := AnsiToUTF8(Sender.AsString);
End;   

Procedure TForm1.InitialiseDataset;
Var
  i: Integer;
  oField: TField;
Begin
  If Not Assigned(FDataset) Then
    Exit;

  For i := 0 To FDataset.FieldCount - 1 Do
  Begin
    oField := FDataset.Fields[i];

    If oField.DataType =ftString Then
      oField.OnGetText := @DatasetOnGetText;
  End;
End; 
 

Then just find an appropriate place to call InitialiseDataset;.  Presumably just after your Dataset.Open;
Lazarus Trunk/FPC Trunk on Windows [7, 10]
  Have you tried searching this forum or the wiki?:   http://wiki.lazarus.freepascal.org/Alternative_Main_Page
  BOOKS! (Free and otherwise): http://wiki.lazarus.freepascal.org/Pascal_and_Lazarus_Books_and_Magazines

taazz

  • Hero Member
  • *****
  • Posts: 5368
Re: win1256
« Reply #8 on: June 12, 2014, 01:25:44 pm »
see there is a place for the workaround to be used after all. But my question was more generic a comment of it does not work or can't be used with data aware controls is to generic there I was only asking for more details in the same spirit of the post.
« Last Edit: June 12, 2014, 01:27:57 pm by taazz »
Good judgement is the result of experience … Experience is the result of bad judgement.

OS : Windows 7 64 bit
Laz: Lazarus 1.4.4 FPC 2.6.4 i386-win32-win32/win64

LacaK

  • Hero Member
  • *****
  • Posts: 691
Re: win1256
« Reply #9 on: June 12, 2014, 01:26:52 pm »
I have a problem using lazarus with mssql,
Which components do you use to connecto to MS SQL Server ?
TMSSQLConnection or TODBCConnection or any others ?

mangakissa

  • Hero Member
  • *****
  • Posts: 1131
Re: win1256
« Reply #10 on: June 12, 2014, 01:35:20 pm »
Quote from: taazz
It doesn't? How is that?
It's exactly what I ment. Mike.Cornflake has a really nice workaround and still is.
If you're a beginner and using not standard UTF8 Lazarus could be 'a pain in the ass'.

I think this is a very old discussion :D
Lazarus 2.06 (64b) / FPC 3.0.4 / Windows 10
stucked on Delphi 10.3.1

Mike.Cornflake

  • Hero Member
  • *****
  • Posts: 1260
Re: win1256
« Reply #11 on: June 12, 2014, 01:38:42 pm »
Hmmm.  I've just noticed that Dataset.OnGetText uses Ansistring for DisplayText...   I'm not that familiar with Unicode issues but from what I understand, this is a potential issue.

@Mhmd60:  If you do try my workaround, could you let us know if it worked or not?

Lazarus Trunk/FPC Trunk on Windows [7, 10]
  Have you tried searching this forum or the wiki?:   http://wiki.lazarus.freepascal.org/Alternative_Main_Page
  BOOKS! (Free and otherwise): http://wiki.lazarus.freepascal.org/Pascal_and_Lazarus_Books_and_Magazines

Mhmd60

  • Newbie
  • Posts: 6
[Solved]: win1256
« Reply #12 on: June 12, 2014, 02:28:49 pm »
First of all, I would like to thank all of you who tried to help me solve my problem, Thank you very very much.
sorry for not telling you that I used zeosdb, but when I converted to mssql connection the problem solved.
You are very kind.
Thank you again.
« Last Edit: November 09, 2016, 07:17:34 pm by Mhmd60 »

 

TinyPortal © 2005-2018