Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-pascal / 2009-01

cross platform version of IsCharAlpha()

16 messages · 9 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Graeme Geldenhuys

Hi,

IsCharAlpha() is a Win32 API call. I'm trying to convert code that uses that call, to be Windows and Linux compatible. Does FPC have a cross-platform version of that API call? I did a text search through the RTL of v2.2.3 and it only seems to have the Windows API version.

I can add a Linux specific function like this in my code, but as the comment says, it is very primitive and clearly not ideal!

function IsCharAlpha(AChar: Char): Boolean;
begin
  // This is very primitive and doesn't take special chars or unicode into
  // consideration.
  if AChar in ['a'..'z', 'A'..'Z'] then
    Result := True
  else
    Result := False;
end;

Anybody got a better Object Pascal version of IsCharAlpha() I can use and that we can add into Free Pascal?

Regards,
- Graeme -

_______________________________________________
fpGUI - a cross-platform Free Pascal GUI toolkit
http://opensoft.homeip.net/fpgui/

Reply by email

ik
to Graeme Geldenhuys

The problem with such function is that it requires a lot of data to be used on a non ANSI table. and you can not use in a unicode implementation the Char type, because a char can be more then one byte.

Ido

Graeme Geldenhuys wrote 36 lines
Hi, IsCharAlpha() is a Win32 API call. I'm trying to convert code that uses that call, to be Windows and Linux compatible. Does FPC have a cross-platform version of that API call? I did a text search through the RTL of v2.2.3 and it only seems to have the Windows API version. I can add a Linux specific function like this in my code, but as the comment says, it is very primitive and clearly not ideal! function IsCharAlpha(AChar: Char): Boolean; begin // This is very primitive and doesn't take special chars or unicode into // consideration. if AChar in ['a'..'z', 'A'..'Z'] then Result := True else Result := False; end; Anybody got a better Object Pascal version of IsCharAlpha() I can use and that we can add into Free Pascal? Regards, - Graeme - _______________________________________________ fpGUI - a cross-platform Free Pascal GUI toolkit http://opensoft.homeip.net/fpgui/ _______________________________________________ fpc-pascal maillist - http://lists.freepascal.org/mailman/listinfo/fpc-pascal

Reply by email

Graeme Geldenhuys
to ik
ik wrote
The problem with such function is that it requires a lot of data to be used on a non ANSI table. and you can not use in a unicode implementation the Char type, because a char can be more then one byte.

I know that all to well. :-) I made a ugly hack just so I can get that ported code working (compilable) under Linux. The Delphi code I am porting is pre-Unicode, so I don't care about Unicode at this moment, but many non-ANSI chars will still fall through the cracks with my implementation. :-(

Regards,
- Graeme -

_______________________________________________
fpGUI - a cross-platform Free Pascal GUI toolkit
http://opensoft.homeip.net/fpgui/

Reply by email

ik
to Graeme Geldenhuys

Because it depends on the code page of the system you are using at the moment you parse the char.

Graeme Geldenhuys wrote 24 lines
On Mon, Jan 12, 2009 at 11:13 AM, ik wrote: > The problem with such function is that it requires a lot of data to be > used on a non ANSI table. and you can not use in a unicode > implementation the Char type, because a char can be more then one > byte. I know that all to well. :-) I made a ugly hack just so I can get that ported code working (compilable) under Linux. The Delphi code I am porting is pre-Unicode, so I don't care about Unicode at this moment, but many non-ANSI chars will still fall through the cracks with my implementation. :-( Regards, - Graeme - _______________________________________________ fpGUI - a cross-platform Free Pascal GUI toolkit http://opensoft.homeip.net/fpgui/ _______________________________________________ fpc-pascal maillist - http://lists.freepascal.org/mailman/listinfo/fpc-pascal

Reply by email

Florian Klaempfl
to Graeme Geldenhuys: IsCharAlpha() is a Win32 API call. I'm trying to convert code that uses that call, to be…
Show quoted text 23 lines
Hi, IsCharAlpha() is a Win32 API call. I'm trying to convert code that uses that call, to be Windows and Linux compatible. Does FPC have a cross-platform version of that API call? I did a text search through the RTL of v2.2.3 and it only seems to have the Windows API version. I can add a Linux specific function like this in my code, but as the comment says, it is very primitive and clearly not ideal! function IsCharAlpha(AChar: Char): Boolean; begin // This is very primitive and doesn't take special chars or unicode into // consideration. if AChar in ['a'..'z', 'A'..'Z'] then Result := True else Result := False; end; Anybody got a better Object Pascal version of IsCharAlpha() I can use and that we can add into Free Pascal?

Add a new entry to the widestring manager, add a implementation to sysutils using the widestring manager. Implement it in the cwstrings for unix and sysutils directly for windows, for unix you can use iswalpha:

http://opengroup.org/onlinepubs/007908775/xsh/iswalpha.html

Create a test and submit a patch :)

Reply by email

Paul Ishenin
to Graeme Geldenhuys: IsCharAlpha() is a Win32 API call. I'm trying to convert code that uses that call, to be…
Graeme Geldenhuys wrote 14 lines
function IsCharAlpha(AChar: Char): Boolean; begin // This is very primitive and doesn't take special chars or unicode into // consideration. if AChar in ['a'..'z', 'A'..'Z'] then Result := True else Result := False; end; Anybody got a better Object Pascal version of IsCharAlpha() I can use and that we can add into Free Pascal?

Here in
http://svn.freepascal.org/svn/lazarus/trunk/components/jcf2/Utils/JcfStringUtils.pas I used the same code :)

Best regards,
Paul Ishenin.

Reply by email

David B Copeland
to Graeme Geldenhuys: IsCharAlpha() is a Win32 API call. I'm trying to convert code that uses that call, to be…

Hi,

I am trying to pre-fill a TComboBox with the all the tables in a database, without sucess. I am running Suse 10.3, a recent (within a week) Lazarus 0.9.27 from svn, FPC 2.2.2, 64-bit. The program uses a ODBCConnection to a MySQL database.

The code I tried is:

  FormMyDB.Query.SQL.Clear;
  FormMyDB.Query.SQL.Add ('show tables;');
  try
      FormMyDB.Query.ExecSQL;
      if FormMyDB.Datasource.DataSet.EOF then
          ShowMessage ('There are no tables!');  // This gets displayed
      while not FormMyDB.Datasource.DataSet.EOF do begin
          CBTable.Items.Add
(FormMyDB.Datasource.DataSet.FieldByName('Tables_in_TRACKER').AsString);
          FormMyDB.Datasource.DataSet.Next
      end;
      FormMyDB.Query.Close;
  except on e: exception do begin
    ShowMessage ('Error load table names: ' + e.message);
    exit;
    end
  end

The ExecSQL appears to complete normally, but the result dataset is empty. What am I doing wrong? In other parts of the program I successfully both query and update various tables in the database. Any pointers in the right direction will be greatly appreciated.

Dave Copeland.

Reply by email

ABorka
to David B Copeland

I think "execsql" never returns any records, you supposed to use "open" for queries returning results.
Execsql is for insert, delete, update, etc.

David B Copeland wrote 39 lines
Hi, I am trying to pre-fill a TComboBox with the all the tables in a database, without sucess. I am running Suse 10.3, a recent (within a week) Lazarus 0.9.27 from svn, FPC 2.2.2, 64-bit. The program uses a ODBCConnection to a MySQL database. The code I tried is: FormMyDB.Query.SQL.Clear; FormMyDB.Query.SQL.Add ('show tables;'); try FormMyDB.Query.ExecSQL; if FormMyDB.Datasource.DataSet.EOF then ShowMessage ('There are no tables!'); // This gets displayed while not FormMyDB.Datasource.DataSet.EOF do begin CBTable.Items.Add (FormMyDB.Datasource.DataSet.FieldByName('Tables_in_TRACKER').AsString); FormMyDB.Datasource.DataSet.Next end; FormMyDB.Query.Close; except on e: exception do begin ShowMessage ('Error load table names: ' + e.message); exit; end end The ExecSQL appears to complete normally, but the result dataset is empty. What am I doing wrong? In other parts of the program I successfully both query and update various tables in the database. Any pointers in the right direction will be greatly appreciated. Dave Copeland. _______________________________________________ fpc-pascal maillist - http://lists.freepascal.org/mailman/listinfo/fpc-pascal

Reply by email

David B Copeland
to ABorka

Ah yes, you are correct. However the the Open returns the following error:

"Query: Cannot open a non-select statement"

I also have found some more help in the Lazarus wiki which just happens to have an example of how to do a "show tables". So then, I tried the following:

  FormMyDB.Query.SQL.Clear;
  FormMyDB.Query.SQL.Text := 'show tables';
  try
      FormMyDB.Query.Open;
      if FormMyDB.Query.EOF then
          ShowMessage ('There are no tables!');
      while not FormMyDB.Query.EOF do begin
          CBTable.Items.Add
(FormMyDB.Datasource.DataSet.FieldByName('Tables_in_TRACKER').AsString);
          FormMyDB.Datasource.DataSet.Next
      end;
      FormMyDB.Query.Close;
  except on e: exception do begin
    ShowMessage ('Error load table names: ' + e.message);
    exit;
    end
  end

Again however the Open returned the same error. Could the problem be that this is supported through a MySQLConnection, but not an ODBC connection?

Dave.

ABorka wrote 51 lines
I think "execsql" never returns any records, you supposed to use "open" for queries returning results. Execsql is for insert, delete, update, etc. David B Copeland wrote: > Hi, > > I am trying to pre-fill a TComboBox with the all the tables in a > database, without sucess. I am running Suse 10.3, a recent (within a > week) Lazarus 0.9.27 from svn, FPC 2.2.2, 64-bit. The program uses a > ODBCConnection to a MySQL database. > > The code I tried is: > > FormMyDB.Query.SQL.Clear; > FormMyDB.Query.SQL.Add ('show tables;'); > try > FormMyDB.Query.ExecSQL; > if FormMyDB.Datasource.DataSet.EOF then > ShowMessage ('There are no tables!'); // This gets displayed > while not FormMyDB.Datasource.DataSet.EOF do begin > CBTable.Items.Add > (FormMyDB.Datasource.DataSet.FieldByName('Tables_in_TRACKER').AsString); > FormMyDB.Datasource.DataSet.Next > end; > FormMyDB.Query.Close; > except on e: exception do begin > ShowMessage ('Error load table names: ' + e.message); > exit; > end > end > > The ExecSQL appears to complete normally, but the result dataset is > empty. What am I doing wrong? In other parts of the program I > successfully both query and update various tables in the database. Any > pointers in the right direction will be greatly appreciated. > > Dave Copeland. > > > _______________________________________________ > fpc-pascal maillist - > http://lists.freepascal.org/mailman/listinfo/fpc-pascal > _______________________________________________ fpc-pascal maillist - http://lists.freepascal.org/mailman/listinfo/fpc-pascal

Reply by email

Joost van der Sluis
to David B Copeland

Op maandag 12-01-2009 om 13:30 uur [tijdzone -0500], schreef David B Copeland:

"Query: Cannot open a non-select statement"

'show tables' is not a valid sql-statement. It is a MySQL-hack. The TODBCConnection can not see that it is connected to a MySQL server and thus doesn't recognise this statement as a select-statement. If you use a TMySQLConnection it will work. You can fill in a bug report to ask if TODBCConnection can recognise 'show' as 'select'. We'll have to look what kind of effect that has on other (really sql-based) database-servers.

btw: To get the list of tables, you can better use TSQLConnection.GetTableNames.

Joost.

Reply by email

Martin Friebe
to Joost van der Sluis
Joost van der Sluis wrote 15 lines
Op maandag 12-01-2009 om 13:30 uur [tijdzone -0500], schreef David B Copeland: > "Query: Cannot open a non-select statement" > 'show tables' is not a valid sql-statement. It is a MySQL-hack. The TODBCConnection can not see that it is connected to a MySQL server and thus doesn't recognise this statement as a select-statement. If you use a TMySQLConnection it will work. You can fill in a bug report to ask if TODBCConnection can recognise 'show' as 'select'. We'll have to look what kind of effect that has on other (really sql-based) database-servers.

If you (the original poster) uses Mysql 5 or up, then "Show tables" is not needed. Use the information-schema instead

SELECT table_name FROM INFORMATION_SCHEMA.TABLES WHERE table_schema = '/|db_name|/'

Reply by email

David B Copeland
to Martin Friebe
Martin Friebe wrote 22 lines
Joost van der Sluis wrote: > Op maandag 12-01-2009 om 13:30 uur [tijdzone -0500], schreef David B > Copeland: > > >> "Query: Cannot open a non-select statement" >> > > 'show tables' is not a valid sql-statement. It is a MySQL-hack. The > TODBCConnection can not see that it is connected to a MySQL server and > thus doesn't recognise this statement as a select-statement. If you use > a TMySQLConnection it will work. You can fill in a bug report to ask if > TODBCConnection can recognise 'show' as 'select'. We'll have to look > what kind of effect that has on other (really sql-based) > database-servers. > If you (the original poster) uses Mysql 5 or up, then "Show tables" is not needed. Use the information-schema instead SELECT table_name FROM INFORMATION_SCHEMA.TABLES WHERE table_schema = '/|db_name|/'

Thanks for all the info. I did try 'show tables' with a TMySQLConnection and found that it worked. But I like the others suggestions. I've found that TMySQLConnection.GetTableNames works like a charm, but that TMySQLConnection.GetTableNames fails with "The metadata is not available for this type of database." I would think the GetTableNames is more portable. So I will file a bug report against GetTableNames.

Dave.

Reply by email

David B Copeland
to Martin Friebe: If you (the original poster) uses Mysql 5 or up, then "Show tables" is not needed. Use…
Martin Friebe wrote 7 lines
> If you (the original poster) uses Mysql 5 or up, then "Show tables" is not needed. Use the information-schema instead SELECT table_name FROM INFORMATION_SCHEMA.TABLES WHERE table_schema = '/|db_name|/'

Yes, I tried this and it works, after setting
TSQLQuery.UsePrimaryKeyAsKey := false since the table information_schema does not have a primary key.

Reply by email

vmars
to Graeme Geldenhuys

'JcfStringUtils.pas' very strange looking code.
Please, what format is the file in?
Thanks!

ô¿ô
V e r n

WinXp sp2 , Delphi5, WebDwarf, Trellian WebPage,
Lazarus-0.9.26-fpc-2.2.2-win32.exe,
wxPython2.8-win32-unicode-2.8.9.1-py26.exe , Boa 0.6.1 http://www.flickr.com/photos/vmars956/

Wanted: Dwarf Hibiscus (Orange/Rasberry)

Earlier message 27 lines
----- Original Message ----- From: "Graeme Geldenhuys" To: "FPC-Pascal users discussions" Sent: Friday, January 23, 2009 2:02 AM Subject: Re: [fpc-pascal] cross platform version of IsCharAlpha() > On Mon, Jan 12, 2009 at 3:39 PM, Paul Ishenin wrote: >> >> Here in >> http://svn.freepascal.org/svn/lazarus/trunk/components/jcf2/Utils/JcfStringUtils.pas >> I used the same code :) > > Thanks Paul, I feel better already! I'm not alone. :-) > > > Regards, > - Graeme - > > > _______________________________________________ > fpGUI - a cross-platform Free Pascal GUI toolkit > http://opensoft.homeip.net/fpgui/ > _______________________________________________ > fpc-pascal maillist - > http://lists.freepascal.org/mailman/listinfo/fpc-pascal >

Reply by email

Graeme Geldenhuys
to vmars
vmars wrote
'JcfStringUtils.pas' very strange looking code. Please, what format is the file in?

Uh? I am using Lazarus 0.9.26 under Linux. The file was opened like any other source file...

Regards,
- Graeme -

_______________________________________________
fpGUI - a cross-platform Free Pascal GUI toolkit
http://opensoft.homeip.net/fpgui/

Reply by email