DBGrid column sort

I have the following code in Delphi XE3 to sort DBGrid columns:

procedure TForm_Display.DBGrid1TitleClick(Column: TColumn);
{$J+}
const PreviouscColumnIndex: integer = -1;
{$J-}
begin
  if DBGrid1.DataSource.DataSet is TCustomADODataSet
  then
    with TCustomADODataSet(DBGrid1.DataSource.DataSet) do
    begin
      try
        DBGrid1.Columns[PreviousColumnIndex].title.Font.Style :=
        DBGrid1.Columns[PreviousColumnIndex].title.Font.Style - [fsBold];
      except
    end;

    Column.title.Font.Style :=
    Column.title.Font.Style + [fsBold];
    PreviousColumnIndex := Column.Index;

    if (Pos(Column.Field.FieldName, Sort) = 1)
    and (Pos(' DESC', Sort)= 0) then
      Sort := Column.Field.FieldName + ' DESC'
    else
      Sort := Column.Field.FieldName + ' ASC';
  end;
end;

I get the following error messages:

[dcc32 Error] Display.pas(67): E2003 Undeclared identifier: 'TCustomADODataSet'
[dcc32 Error] Display.pas(68): E2015 Operator not applicable to this operand type
[dcc32 Error] Display.pas(72): E2003 Undeclared identifier: 'PreviousColumnIndex'
[dcc32 Error] Display.pas(81): E2003 Undeclared identifier: 'Sort'
[dcc32 Warning] Display.pas(81): W1058 Implicit string cast with potential data loss from 'string' to 'ShortString'
[dcc32 Error] Display.pas(82): E2250 There is no overloaded version of 'Pos' that can be called with these arguments
[dcc32 Fatal Error] F2063 Could not compile used unit 'Display.pas'
0
Mervin
7/14/2014 12:54:43 AM
embarcadero.delphi.ado 597 articles. 1 followers. Follow

1 Replies
1668 Views

Similar Articles

[PageSpeed] 20

> {quote:title=Mervin Norton wrote:}{quote}
> I have the following code in Delphi XE3 to sort DBGrid columns:
> 
> procedure TForm_Display.DBGrid1TitleClick(Column: TColumn);
> {$J+}
> const PreviouscColumnIndex: integer = -1;
> {$J-}
> begin
>   if DBGrid1.DataSource.DataSet is TCustomADODataSet
>   then
>     with TCustomADODataSet(DBGrid1.DataSource.DataSet) do
>     begin
>       try
>         DBGrid1.Columns[PreviousColumnIndex].title.Font.Style :=
>         DBGrid1.Columns[PreviousColumnIndex].title.Font.Style - [fsBold];
>       except
>     end;
> 
>     Column.title.Font.Style :=
>     Column.title.Font.Style + [fsBold];
>     PreviousColumnIndex := Column.Index;
> 
>     if (Pos(Column.Field.FieldName, Sort) = 1)
>     and (Pos(' DESC', Sort)= 0) then
>       Sort := Column.Field.FieldName + ' DESC'
>     else
>       Sort := Column.Field.FieldName + ' ASC';
>   end;
> end;
> 
> I get the following error messages:
> 
> [dcc32 Error] Display.pas(67): E2003 Undeclared identifier: 'TCustomADODataSet'
> [dcc32 Error] Display.pas(68): E2015 Operator not applicable to this operand type
> [dcc32 Error] Display.pas(72): E2003 Undeclared identifier: 'PreviousColumnIndex'
> [dcc32 Error] Display.pas(81): E2003 Undeclared identifier: 'Sort'
> [dcc32 Warning] Display.pas(81): W1058 Implicit string cast with potential data loss from 'string' to 'ShortString'
> [dcc32 Error] Display.pas(82): E2250 There is no overloaded version of 'Pos' that can be called with these arguments
> [dcc32 Fatal Error] F2063 Could not compile used unit 'Display.pas'

Couple of things 
1) Include unit Data.Win.ADODB (that's what it called in XE4 - just search in nthe source directory for TCustomADODataSet or drop an adoData set on your form Compile and then remove - it 'll ddd the correct reference
2) const PreviouscColumnIndex: <> PreviousColumnIndex DOUBLE cC in the declaration

That will fix a lot of them
--
Linden
"Mango" was Cool but "Wasabi" was Hotter but remember it's all in the "source"
0
Linden
7/14/2014 2:13:09 AM
Reply:

Similar Artilces:

DBgrid Sort by Column
I am trying to do a DBGrid sort by column utilizing clientdatasets and changing the indexes. I am getting "Exception class EAccessViolation with message 'Access violation at address 005C48)d in module 'Orca2.exe'. Read of address 00000030'. Process Orca2exe (7460)' Seems to be hanging on Field := ClientDataSet.Fields.FindField(FieldName); second statement down from begin. It also appears as though FieldName does contain a valid column name. I am kind of at a loss as how to proceed. function SortClientDataSet(ClientDataSet: TClientDataSet; const Fi...

Datagrid sort -Sorting a column which is mapped to database column
How do I sort a datagrid column ,which is not mapped to database column. I'm able to sort other columns from the same datagrid which are mapped to database column and this grid has one of the columns which is not mapped to database column. But need to know how to sort the column which is not mapped to database column.     needtoknow: How do I sort a datagrid column ,which is not mapped to database column. I'm able to sort other columns from the same datagrid which are mapped to database column and this grid has one of the columns which is not mapped to database ...

Convert Delphi 5 ADO App to Delphi 2007 ADO.NET
I have an appliction tha that is writen in Delphi 5 with ADOConnetion, ADOTable, and ADOQuery components. I need to upgrade to Delphi 2007 and use ADO.NET. I have the program building in with Delphi 2007. Is there anything I need to do to convert the ADO to ADO.NET? > I need to upgrade to Delphi 2007 and use ADO.NET. Why ? -- With best regards, Dmitry Arefiev AnyDAC (www.anydac.com) - Oracle, MS SQL Server, IBM DB2, MySQL, Firebird, Interbase, PostgreSQL, Sybase ASA, SQLite, MS Access, DBX, ODBC, InMem - universal high-speed native data access engine Reasons for ...

DBGrid and Column Title Sort Indicator?
w/D7 Pro: Is there anyway to get that shadow effect up/down arrow in the DBGrid's Column Title cell with the default component... ....or do I have to use some extended third-party? Barry >Is there anyway to get that shadow effect up/down arrow in the >DBGrid's Column Title cell with the default component... You can do, but the best way to see how is to look at one of the components that does it <g> >...or do I have to use some extended third-party? Check out SMDBGrid from http://www.scalabium.com/ - its free with source. I used it for a long time be...

How to sort records in Delphi DBGrid [Edit]
I need to alphabetically sort records in the TDBGrid at run-time I don't want to sort records from the Table or Dataset because that is my main sort index. I can't seem to work this out can someone help please? I am using Delphi 7 it really works for me. Edited by: unit4 P on Aug 11, 2012 3:10 PM Edited by: unit4 P on Aug 11, 2012 4:38 PM On 12/08/2012 9:38 AM, unit4 P wrote: > I need to alphabetically sort records in the TDBGrid at run-time > I don't want to sort records from the Table or Dataset because that is my main sort index. > > I can't se...

Sorting Columns within columns
In sent items, I need to be able to sort first by 'To' and then by 'Date' so that all mail sent to one person is grouped together and in date order. (Bit like the sort you can do in Excel).There only appears to be one sort option. Any ideas anyone? Sort by date first, then by the To, as Sorts normally do a minimum movement approach, that should get you what you want, but it would always be a manual process - you can't store the double sort Cheers Dave -- Dave Parkes [NSCS] Occasionally resident at http://support-forums.novell.com/ You can regist...

How I sort the gridview column after column
I have the following columns in my gridview(VB) Type   FirstName   LastName    Company   City How I can sort the gridview firstly by column 1, after that by column 2 and so on. Thanks in advance.   You can write your SQL SELECT statement this way: SELECT Type ,  FirstName,   LastName,    Company,   City  FROM yourtable ORDER BY 1 ASC, 2, 3,4, 5 OR SELECT Type,  FirstName,   LastName,    Company,   City  FROM yourtable ORDER BY  Type&...

Delphi 2010
Hi With new Delphi 2010 code i can't have a Dbgrid with ColumnClick event and column header Themed. i have see a new option in dbgrid : dgTitleClick :( if i active this property i lost themed blue rettangule when i move mouse over the column header ( it is like a very old dbgrid ) i'm using ThemedDBGrid unit , but don't work more in D2010 ( column header not Themed with OnTitleClick Assigned and dgTitleClick set to True ) How i can active ALL FEATURES of THEMED with OnTitleClick Assigned ? Edited by: Mauro Botta on Oct 13, 2009 11:54 AM upppp...

Delphi 2009: DBGrid column sizes changed in Windows 7
I have a problem with our application made with Delpi 2009 (in XP) when I deliver it to Windows 7 PC. It seems that width of columns are for some reason changed in windows 7 so that now the size of DBGrid itself is bigger than all columns together (empty space in right side of DBGrid). In XP PC all objects are in correct size. The problem is that our SW development environment is XP and we are doing application version for W7 so the actual problem comes visible only after application is installed into W7 PC. We have tried several different methods without success yet. If somebody has faced s...

Delphi 7 with ADO DBGrid, entering contents of record into variables. [Edit]
Hi there, For my A-Level computing coursework I'm using a Delphi front-end on an MS Access Database, to store information on customers and create an invoice for them, by calculating data within the database. Basically my problem is this: Is there a way that the user can select a specific record within a DBGrid component, and then have a procedure that will assign the contents of each field for this specific record into a separate variable? E.g. the Record goes like Name: John Smith Date of Birth: 04/09/2005, and when that record is selected, the data contained within nam...

Header column sorting
Hello all ; We have a u_dw with 5 columns one column have edit style of dddw. When we sorting this column by clicking it's header it's sorts the column by it's code and not by the display column. How can we change that behavior , that the sorting will sort by the display value ? Thanks Ronens@jazo.org.il Here's one generic solution: For all dddw's, add a computed column with a standard name such as <dddw_column_name>_display. For the expression use "LookUpDisplay ( column )". Extend PFC to check for exis...

Sort on column without highlighting the column
Hi there, I have a grid style datawindow and when I click the column header in order to sort the data the entire column is selected (highlighted). Is there a way to sort by clicking on the column header but without highlighting the entire column? Thanks, Gerry. An aside. I can turn the grid property off, but then I loose the capability to move and resize the columns. Gerry. On 21 Apr 2004 09:35:52 -0700, Gerry <gerico@xs4all.nl> wrote: >Hi there, > >I have a grid style datawindow and when I click the column header in >order to sort the data the enti...

Sorting columns when displaying single column in DataList
Currently, I am using the DataList to display the data. My DataList code looks something like this:<datalist><itemTemplate><tr><td>Name:</td><td><% DataBinder.....%></td></tr><tr><td>Company:</td><td><% DataBinder.....%></td></tr></itemTemplate></datalist>  My question is: How can I have an easy way of sorting this data. I would like the users to be able to sort the data by Name or by Company. I understand I can add AllowSorting to DataList or DataGrid, but then I would have to di...

Delphi 6 to Delphi 2010 upgrade and ADO
We have an application written in Delphi 6 Professional that uses ADO to access databases servers that may be on other PCs in our network. We want to move to Delphi 2010 but can't decide if we need Professional or Enterprise. 2010 Pro has dbGO - will this give us the same functionality as the ADO components we use in Delphi 6 Pro? Thanks, Keith > 2010 Pro has dbGO - will this give us the same functionality as the > ADO components we use in Delphi 6 Pro? Yes. > {quote:title=Joachim Uersfeld wrote:}{quote} > > 2010 Pro has dbGO - will this give us the same func...

Web resources about - DBGrid column sort - embarcadero.delphi.ado

FireMonkey Q&A
Questions and answers from a FireMonkey webinar

Apollo - Testimonials
Apollo embedded database engine for managing CA-Clipper, FoxPro, Xbase, DBF database, index and memo files using C#, VB.NET, Delphi, C++Builder, ...

IDE Fix Pack 2007 4.4 - Andy's Blog and Tools
Andy's Blog and Tools Delphi, C++Builder and other thoughts Skip to content Home IDE Tools DDevExtensions 2.6 IDE Fix Pack 5.1 IDE Fix Pack 2007 ...

DBGrid sample dbgridtest
DB Off Line To access the SETI Net data in real time:1. Click Connec To Cloud dB - opens the SETI Net database on a cloud server2. Wait for 'Off ...

OpenSource Units - Andy's Blog and Tools
Andy's Blog and Tools Delphi, C++Builder and other thoughts Skip to content Home IDE Tools DDevExtensions 2.6 IDE Fix Pack 5.1 IDE Fix Pack 2007 ...

Resources last updated: 1/21/2016 6:11:55 PM