added 'search by grid column' function

This commit is contained in:
rickarof 2018-08-22 11:35:50 -03:00
parent 89639700ce
commit abc715fd8d
12 changed files with 235 additions and 215 deletions

View File

@ -9,7 +9,9 @@ uses
UnitFormEstado in 'UnitFormEstado.pas' {FormEstado},
UnitFormPais in 'UnitFormPais.pas' {FormPais},
UnitFormGrid in 'UnitFormGrid.pas' {FormGrid},
UnitDados in 'UnitDados.pas';
UnitDados in 'UnitDados.pas',
Vcl.Themes,
Vcl.Styles;
{$R *.res}

View File

@ -46,6 +46,7 @@
<Base>true</Base>
</PropertyGroup>
<PropertyGroup Condition="'$(Base)'!=''">
<Custom_Styles>Amakrits|VCLSTYLE|$(PUBLIC)\Documents\Embarcadero\Studio\17.0\Styles\Amakrits.vsf;&quot;Amethyst Kamri|VCLSTYLE|$(PUBLIC)\Documents\Embarcadero\Studio\17.0\Styles\AmethystKamri.vsf&quot;;&quot;Aqua Graphite|VCLSTYLE|$(PUBLIC)\Documents\Embarcadero\Studio\17.0\Styles\AquaGraphite.vsf&quot;;&quot;Aqua Light Slate|VCLSTYLE|$(PUBLIC)\Documents\Embarcadero\Studio\17.0\Styles\AquaLightSlate.vsf&quot;;Auric|VCLSTYLE|$(PUBLIC)\Documents\Embarcadero\Studio\17.0\Styles\Auric.vsf;Carbon|VCLSTYLE|$(PUBLIC)\Documents\Embarcadero\Studio\17.0\Styles\Carbon.vsf;&quot;Charcoal Dark Slate|VCLSTYLE|$(PUBLIC)\Documents\Embarcadero\Studio\17.0\Styles\CharcoalDarkSlate.vsf&quot;;&quot;Cobalt XEMedia|VCLSTYLE|$(PUBLIC)\Documents\Embarcadero\Studio\17.0\Styles\CobaltXEMedia.vsf&quot;;&quot;Cyan Dusk|VCLSTYLE|$(PUBLIC)\Documents\Embarcadero\Studio\17.0\Styles\CyanDusk.vsf&quot;;&quot;Cyan Night|VCLSTYLE|$(PUBLIC)\Documents\Embarcadero\Studio\17.0\Styles\CyanNight.vsf&quot;;&quot;Emerald Light Slate|VCLSTYLE|$(PUBLIC)\Documents\Embarcadero\Studio\17.0\Styles\EmeraldLightSlate.vsf&quot;;Glossy|VCLSTYLE|$(PUBLIC)\Documents\Embarcadero\Studio\17.0\Styles\Glossy.vsf;Glow|VCLSTYLE|$(PUBLIC)\Documents\Embarcadero\Studio\17.0\Styles\Glow.vsf;&quot;Golden Graphite|VCLSTYLE|$(PUBLIC)\Documents\Embarcadero\Studio\17.0\Styles\GoldenGraphite.vsf&quot;;&quot;Iceberg Classico|VCLSTYLE|$(PUBLIC)\Documents\Embarcadero\Studio\17.0\Styles\IcebergClassico.vsf&quot;;&quot;Lavender Classico|VCLSTYLE|$(PUBLIC)\Documents\Embarcadero\Studio\17.0\Styles\LavenderClassico.vsf&quot;;Light|VCLSTYLE|$(PUBLIC)\Documents\Embarcadero\Studio\17.0\Styles\Light.vsf;Luna|VCLSTYLE|$(PUBLIC)\Documents\Embarcadero\Studio\17.0\Styles\Luna.vsf;&quot;Metropolis UI Black|VCLSTYLE|$(PUBLIC)\Documents\Embarcadero\Studio\17.0\Styles\MetropolisUIBlack.vsf&quot;;&quot;Metropolis UI Blue|VCLSTYLE|$(PUBLIC)\Documents\Embarcadero\Studio\17.0\Styles\MetropolisUIBlue.vsf&quot;;&quot;Metropolis UI Dark|VCLSTYLE|$(PUBLIC)\Documents\Embarcadero\Studio\17.0\Styles\MetropolisUIDark.vsf&quot;;&quot;Metropolis UI Green|VCLSTYLE|$(PUBLIC)\Documents\Embarcadero\Studio\17.0\Styles\MetropolisUIGreen.vsf&quot;;Obsidian|VCLSTYLE|$(PUBLIC)\Documents\Embarcadero\Studio\17.0\Styles\Obsidian.vsf;&quot;Onyx Blue|VCLSTYLE|$(PUBLIC)\Documents\Embarcadero\Studio\17.0\Styles\OnyxBlue.vsf&quot;;&quot;Ruby Graphite|VCLSTYLE|$(PUBLIC)\Documents\Embarcadero\Studio\17.0\Styles\RubyGraphite.vsf&quot;;&quot;Sapphire Kamri|VCLSTYLE|$(PUBLIC)\Documents\Embarcadero\Studio\17.0\Styles\SapphireKamri.vsf&quot;;Silver|VCLSTYLE|$(PUBLIC)\Documents\Embarcadero\Studio\17.0\Styles\Silver.vsf;Sky|VCLSTYLE|$(PUBLIC)\Documents\Embarcadero\Studio\17.0\Styles\Sky.vsf;&quot;Slate Classico|VCLSTYLE|$(PUBLIC)\Documents\Embarcadero\Studio\17.0\Styles\SlateClassico.vsf&quot;;&quot;Smokey Quartz Kamri|VCLSTYLE|$(PUBLIC)\Documents\Embarcadero\Studio\17.0\Styles\SmokeyQuartzKamri.vsf&quot;;&quot;Tablet Light|VCLSTYLE|$(PUBLIC)\Documents\Embarcadero\Studio\17.0\Styles\TabletLight.vsf&quot;;TabletDark|VCLSTYLE|$(PUBLIC)\Documents\Embarcadero\Studio\17.0\Styles\TabletDark.vsf;&quot;Turquoise Gray|VCLSTYLE|$(PUBLIC)\Documents\Embarcadero\Studio\17.0\Styles\TurquoiseGray.vsf&quot;;Windows10|VCLSTYLE|$(PUBLIC)\Documents\Embarcadero\Studio\17.0\Styles\Windows10.vsf;&quot;Windows10 Blue|VCLSTYLE|$(PUBLIC)\Documents\Embarcadero\Studio\17.0\Styles\Windows10Blue.vsf&quot;;&quot;Windows10 Dark|VCLSTYLE|$(PUBLIC)\Documents\Embarcadero\Studio\17.0\Styles\Windows10Dark.vsf&quot;</Custom_Styles>
<SanitizedProjectName>Project1</SanitizedProjectName>
<Icon_MainIcon>$(BDS)\bin\delphi_PROJECTICON.ico</Icon_MainIcon>
<DCC_Namespace>System;Xml;Data;Datasnap;Web;Soap;Vcl;Vcl.Imaging;Vcl.Touch;Vcl.Samples;Vcl.Shell;$(DCC_Namespace)</DCC_Namespace>
@ -157,12 +158,27 @@
<Overwrite>true</Overwrite>
</Platform>
</DeployFile>
<DeployClass Name="ProjectiOSDeviceResourceRules">
<DeployClass Name="DependencyModule">
<Platform Name="Win32">
<Operation>0</Operation>
<Extensions>.dll;.bpl</Extensions>
</Platform>
<Platform Name="iOSDevice64">
<Operation>1</Operation>
<Extensions>.dylib</Extensions>
</Platform>
<Platform Name="OSX32">
<RemoteDir>Contents\MacOS</RemoteDir>
<Operation>1</Operation>
<Extensions>.dylib</Extensions>
</Platform>
<Platform Name="iOSDevice32">
<Operation>1</Operation>
<Extensions>.dylib</Extensions>
</Platform>
<Platform Name="iOSSimulator">
<Operation>1</Operation>
<Extensions>.dylib</Extensions>
</Platform>
</DeployClass>
<DeployClass Name="ProjectOSXResource">
@ -516,27 +532,12 @@
<Operation>1</Operation>
</Platform>
</DeployClass>
<DeployClass Name="DependencyModule">
<Platform Name="Win32">
<Operation>0</Operation>
<Extensions>.dll;.bpl</Extensions>
</Platform>
<DeployClass Name="ProjectiOSDeviceResourceRules">
<Platform Name="iOSDevice64">
<Operation>1</Operation>
<Extensions>.dylib</Extensions>
</Platform>
<Platform Name="OSX32">
<RemoteDir>Contents\MacOS</RemoteDir>
<Operation>1</Operation>
<Extensions>.dylib</Extensions>
</Platform>
<Platform Name="iOSDevice32">
<Operation>1</Operation>
<Extensions>.dylib</Extensions>
</Platform>
<Platform Name="iOSSimulator">
<Operation>1</Operation>
<Extensions>.dylib</Extensions>
</Platform>
</DeployClass>
<ProjectRoot Platform="iOSDevice64" Name="$(PROJECTNAME).app"/>

View File

@ -1,10 +1,10 @@
[Stats]
EditorSecs=62163
DesignerSecs=6844
InspectorSecs=2376
CompileSecs=373514
OtherSecs=2081
EditorSecs=62883
DesignerSecs=7804
InspectorSecs=3050
CompileSecs=388395
OtherSecs=2182
StartTime=03/08/2018 07:57:26
RealKeys=0
EffectiveKeys=0
DebugSecs=28213
DebugSecs=28776

View File

@ -7,6 +7,7 @@ inherited FormCidade: TFormCidade
TextHeight = 18
inherited ToolBar1: TToolBar
Width = 600
ExplicitWidth = 600
inherited btAnterior: TButton
TabOrder = 2
OnClick = btAnteriorClick
@ -33,42 +34,42 @@ inherited FormCidade: TFormCidade
end
inherited Panel1: TPanel
Width = 600
ExplicitHeight = 260
ExplicitWidth = 600
DesignSize = (
600
243)
inherited Panel2: TPanel
object Label1: TLabel [0]
Left = 70
Left = 75
Top = 20
Width = 50
Height = 25
Width = 45
Height = 18
Alignment = taRightJustify
Anchors = []
Caption = 'C'#243'digo:'
end
object Label2: TLabel [1]
Left = 70
Left = 75
Top = 70
Width = 50
Height = 25
Width = 45
Height = 18
Alignment = taRightJustify
Anchors = []
Caption = 'Cidade:'
end
object Label3: TLabel [2]
Left = 70
Left = 92
Top = 120
Width = 50
Height = 25
Width = 28
Height = 18
Alignment = taRightJustify
Caption = 'Pa'#237's:'
end
object Label4: TLabel [3]
Left = 300
Left = 330
Top = 120
Width = 50
Height = 25
Width = 20
Height = 18
Alignment = taRightJustify
Anchors = []
Caption = 'UF:'
@ -126,6 +127,7 @@ inherited FormCidade: TFormCidade
Text = 'Aguardando'
Width = 50
end>
ExplicitTop = 293
ExplicitTop = 284
ExplicitWidth = 600
end
end

View File

@ -28,7 +28,6 @@ type
procedure btExportarClick(Sender: TObject);
procedure btImportarClick(Sender: TObject);
procedure btContarClick(Sender: TObject);
procedure Button1Click(Sender: TObject);
procedure edCodExit(Sender: TObject);
procedure edFinalKeyPress(Sender: TObject; var Key: Char);
procedure limpaCampos();
@ -127,12 +126,6 @@ begin
end;
end;
procedure TFormCidade.Button1Click(Sender: TObject);
begin
inherited;
ShowMessage('teste');
end;
procedure TFormCidade.cbLimparCamposClick(Sender: TObject);
begin
inherited;

View File

@ -1,8 +1,8 @@
object FormGrid: TFormGrid
Left = 0
Top = 0
Width = 448
Height = 418
Width = 350
Height = 350
AutoScroll = True
Caption = 'FormGrid'
Color = clBtnFace
@ -16,30 +16,36 @@ object FormGrid: TFormGrid
Visible = True
OnClose = FormClose
OnCreate = FormCreate
OnKeyPress = FormKeyPress
PixelsPerInch = 96
TextHeight = 18
object StringGrid1: TStringGrid
Left = 0
Top = 59
Width = 265
Height = 222
Top = 41
Width = 334
Height = 247
Align = alClient
ColCount = 4
DrawingStyle = gdsClassic
FixedCols = 0
FixedRows = 0
Options = [goFixedVertLine, goFixedHorzLine, goVertLine, goHorzLine, goRangeSelect, goEditing]
Options = [goFixedVertLine, goFixedHorzLine, goVertLine, goHorzLine, goRangeSelect, goDrawFocusSelected]
ParentShowHint = False
ShowHint = True
TabOrder = 0
OnKeyPress = StringGrid1KeyPress
ExplicitTop = 36
ExplicitHeight = 251
end
object ToolBar1: TToolBar
Left = 0
Top = 0
Width = 432
Height = 29
Width = 334
Height = 41
ButtonHeight = 30
Caption = 'ToolBar1'
TabOrder = 1
ExplicitWidth = 384
object btExcluir: TButton
Left = 0
Top = 0
@ -71,13 +77,21 @@ object FormGrid: TFormGrid
TabOrder = 1
OnClick = btEscolherClick
end
end
object edPesquisa: TEdit
Left = 64
Top = 35
Width = 70
Height = 26
object edKeyPress: TEdit
Left = 150
Top = 0
Width = 111
Height = 30
Enabled = False
TabOrder = 2
OnChange = edPesquisaChange
TextHint = 'Pesquisa'
end
end
object StatusBar1: TStatusBar
Left = 0
Top = 288
Width = 334
Height = 23
Panels = <>
end
end

View File

@ -13,16 +13,20 @@ type
ToolBar1: TToolBar;
btExcluir: TButton;
btEscolher: TButton;
edPesquisa: TEdit;
edKeyPress: TEdit;
StatusBar1: TStatusBar;
procedure geraGrid(Lista: TLista; Classe: TClass);
procedure FormClose(Sender: TObject; var Action: TCloseAction);
procedure btExcluirClick(Sender: TObject);
procedure btEscolherClick(Sender: TObject);
procedure edPesquisaChange(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure FormKeyPress(Sender: TObject; var Key: Char);
procedure StringGrid1KeyPress(Sender: TObject; var Key: Char);
procedure limpaGrid();
private
{ Private declarations }
palavra: string;
palavraPesquisa: string;
public
{ Public declarations }
end;
@ -37,6 +41,16 @@ implementation
{$R *.dfm}
uses UnitFormCidade;
procedure TFormGrid.limpaGrid;
var
linha: integer;
begin
for linha:= 1 to StringGrid1.RowCount -1 do
begin
StringGrid1.Rows[linha].Clear; //Cells[coluna,linha]:='';
end;
end;
procedure TFormGrid.btEscolherClick(Sender: TObject);
var
wObj: TObject;
@ -69,142 +83,6 @@ begin
end;
procedure TFormGrid.edPesquisaChange(Sender: TObject);
var
wCont: integer;
wObj: TObject;
wLista: TLista;
linha: integer;
begin
palavra := edPesquisa.Text;
if palavra <> '' then
begin
wLista := TLista.Create;
for wCont := 0 to FLista.Count-1 do
begin
wObj := FLista.getObjectByIndex(wCont);
if wObj.ClassType = TCidade then
begin
with wObj as TCidade do
begin
if ContainsText(wCidade, palavra) then
begin
wLista.Inserir(wObj, TCidade);
end;
end;
end
else
if wObj.ClassType = TEstado then
begin
with wObj as TEstado do
begin
if ContainsText (wEstado, palavra) then
begin
wLista.Inserir(wObj, TEstado);
end;
end;
end
else
if wObj.ClassType = TPais then
begin
with wObj as TPais do
begin
if ContainsText (wPais, palavra) then
begin
wLista.Inserir(wObj, TPais);
end;
end;
end;
end;
if wLista.Count > 0 then
begin
for linha:= 1 to StringGrid1.RowCount -1 do
begin
StringGrid1.Rows[linha].Clear; //Cells[coluna,linha]:='';
end;
StringGrid1.RowCount := wLista.Count;
for wCont := 0 to wLista.Count-1 do
begin
wObj := wLista.getObjectByIndex(wCont);
if wObj.ClassType = TCidade then
begin
with wObj as TCidade do
begin
StringGrid1.Cells[0, wCont] := inttostr(wCod);
StringGrid1.Cells[1, wCont] := wCidade;
StringGrid1.Cells[2, wCont] := wPais;
StringGrid1.Cells[3, wCont] := wUF;
end;
end
else
if wObj.ClassType = TEstado then
begin
with wObj as TEstado do
begin
StringGrid1.Cells[0, wCont] := inttostr(wCod);
StringGrid1.Cells[1, wCont] := wEstado;
StringGrid1.Cells[2, wCont] := wPais;
StringGrid1.Cells[3, wCont] := inttostr(wAliquota);
end;
end
else
if wObj.ClassType = TPais then
begin
with wObj as Tpais do
begin
StringGrid1.Cells[0, wCont] := inttostr(wCod);
StringGrid1.Cells[1, wCont] := wPais;
StringGrid1.Cells[2, wCont] := wNacionalidade;
StringGrid1.Cells[3, wCont] := inttostr(wCodfed);
end;
end;
end;
end;
end
else
begin
StringGrid1.RowCount := Flista.Count;
for wCont := 0 to FLista.Count-1 do
begin
wObj := FLista.getObjectByIndex(wCont);
if wObj.ClassType = TCidade then
begin
with wObj as TCidade do
begin
StringGrid1.Cells[0, wCont] := inttostr(wCod);
StringGrid1.Cells[1, wCont] := wCidade;
StringGrid1.Cells[2, wCont] := wPais;
StringGrid1.Cells[3, wCont] := wUF;
end;
end
else
if wObj.ClassType = TEstado then
begin
with wObj as TEstado do
begin
StringGrid1.Cells[0, wCont] := inttostr(wCod);
StringGrid1.Cells[1, wCont] := wEstado;
StringGrid1.Cells[2, wCont] := wPais;
StringGrid1.Cells[3, wCont] := inttostr(wAliquota);
end;
end
else
if wObj.ClassType = TPais then
begin
with wObj as TPais do
begin
StringGrid1.Cells[0, wCont] := inttostr(wCod);
StringGrid1.Cells[1, wCont] := wPais;
StringGrid1.Cells[2, wCont] := wNacionalidade;
StringGrid1.Cells[3, wCont] := inttostr(wCodFed);
end;
end;
end;
end;
end;
procedure TFormGrid.FormClose(Sender: TObject; var Action: TCloseAction);
begin
Action := caFree;
@ -215,6 +93,13 @@ begin
checkList := true;
end;
procedure TFormGrid.FormKeyPress(Sender: TObject; var Key: Char);
begin
edKeyPress.Text := Key;
ShowMessage(key);
ShowMessage('teste');
end;
procedure TFormGrid.geraGrid(Lista: TLista; Classe: TClass);
var
wCont: integer;
@ -238,7 +123,8 @@ begin
StringGrid1.Cells[1, wCont] := wCidade;
StringGrid1.Cells[2, wCont] := wPais;
StringGrid1.Cells[3, wCont] := wUF;
end;
end
else
if wObj.ClassType = TEstado then
with wObj as TEstado do
begin
@ -246,7 +132,8 @@ begin
StringGrid1.Cells[1, wCont] := wEstado;
StringGrid1.Cells[2, wCont] := wPais;
StringGrid1.Cells[3, wCont] := inttostr(wAliquota);
end;
end
else
if wObj.ClassType = TPais then
with wObj as TPais do
begin
@ -258,4 +145,125 @@ begin
end;
end;
procedure TFormGrid.StringGrid1KeyPress(Sender: TObject; var Key: Char);
var
wObj: TObject;
wCol: integer;
wLista: TLista;
wCont: Integer;
begin
if ord(Key) = 8 then
begin
edKeyPress.Text := '';
limpaGrid();
StringGrid1.RowCount := FLista.Count;
for wCont := 0 to Flista.Count-1 do
begin
wObj := FLista.getObjectByIndex(wCont);
if wObj.ClassType = TCidade then
begin
with wObj as TCidade do
begin
StringGrid1.Cells[0, wcont] := inttostr(wCod);
StringGrid1.Cells[1, wCont] := wCidade;
StringGrid1.Cells[2, wCont] := wPais;
StringGrid1.Cells[3, wCont] := wUF;
end;
end
else
if wObj.ClassType = TEstado then
begin
with wObj as TEstado do
begin
StringGrid1.Cells[0, wcont] := inttostr(wCod);
StringGrid1.Cells[1, wCont] := wEstado;
StringGrid1.Cells[2, wCont] := wPais;
StringGrid1.Cells[3, wCont] := inttostr(wAliquota);
end;
end
else
if wObj.ClassType = TPais then
begin
with wObj as TPais do
begin
StringGrid1.Cells[0, wcont] := inttostr(wCod);
StringGrid1.Cells[1, wCont] := wPais;
StringGrid1.Cells[2, wCont] := wNacionalidade;
StringGrid1.Cells[3, wCont] := inttostr(wCodFed);
end;
end;
end;
end
else
begin
edKeyPress.Text := edKeyPress.Text + key;
wCol :=StringGrid1.Col;
wLista := TLista.Create;
for wCont := 0 to FLista.Count-1 do
begin
wObj := FLista.getObjectByIndex(wCont);
if wObj.ClassType = TCidade then
begin
with wObj as TCidade do
if (wCol = 0) and (ContainsText (inttostr(wCod), edKeyPress.Text)) then
wLista.Inserir(wObj, TCidade)
else
if (wCol = 1) and (ContainsText (wCidade, edKeyPress.Text)) then
wLista.Inserir(wObj, TCidade)
else
if (wCol = 2) and (ContainsText (wPais, edKeyPress.Text)) then
wLista.Inserir(wObj, TCidade)
else
if (wCol = 3) and (ContainsText (wUF, edKeyPress.Text)) then
wLista.Inserir(wObj, TCidade);
end
else
if wObj.ClassType = TEstado then
begin
with wObj as TEstado do
if (wCol =0) and (ContainsText (inttostr(wCod), edKeypress.Text)) then
wLista.Inserir(wObj, TEstado)
else
if (wCol =1) and (ContainsText(wEstado, edkeyPress.Text)) then
wLista.Inserir(wObj, TEstado)
else
if (wCol =2) and (ContainsText(wPais, edKeyPress.Text)) then
wLista.Inserir(wObj, TEstado)
else
if (wCol =3) and (ContainsText(inttostr(wAliquota), edKeyPress.Text)) then
wLista.Inserir(wObj, TEstado);
end
else
if wObj.ClassType = TPais then
begin
end;
end;
if wLista.Count > 0 then
begin
limpaGrid();
StringGrid1.RowCount := wLista.Count;
for wCont := 0 to wLista.Count-1 do
begin
wObj := wLista.getObjectByIndex(wCont);
if wObj.ClassType = TCidade then
begin
with wObj as TCidade do
begin
StringGrid1.Cells[0, wCont] := inttostr(wCod);
StringGrid1.Cells[1, wCont] := wCidade;
StringGrid1.Cells[2, wCont] := wPais;
StringGrid1.Cells[3, wCont] := wUF;
end;
end;
end;
end;
end;
end;
end.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.