来来来,看看你的水平有多高!——Aimingoo送分项目(超过600大元) (0分)

  • 主题发起人 aimingoo
  • 开始时间
Y

yyanghhong

Unregistered / Unconfirmed
GUEST, unregistred user!
Hi all
it is a database application, i use do
A and ttreeview to built a tree structure,
it is simple, but it is useful, The table name of oracle is tree_tab, the fields are
p_key(number),c_key(number),val(varchar).
the record in the table is like below.
p_key, c_key, val
1 3 a3
2 4 a4
1 2 a2
...
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
ComCtrls, Oracle;
type
TForm1 = class(TForm)
OracleSession1: TOracleSession;
OracleQuery1: TOracleQuery;
TreeView1: TTreeView;
Button1: TButton;
procedure Button1Click(Sender: TObject);
procedure TreeView1Click(Sender: TObject);

private
public
end;

var
Form1: TForm1;
implementation
{$R *.DFM}
procedure TForm1.Button1Click(Sender: TObject);
var
TreeNode_list:array of ttreenode;
last_level:integer;
begin
with oraclequery1,treeview1.items do
begin
sql.Clear;
Clear;
sql.add('select level,c_key,val ');
sql.add(' from tree_tab ');
sql.add(' start with p_key= 1 ');
sql.add(' CONNECT BY PRIOR c_key=p_key ');
execute;
last_level:=0;
setlength(TreeNode_list,1);
TreeNode_list[0] := AddObject(nil, 'Root', pointer(1));
while not eof do
begin
if fieldasinteger('level')>last_level then
begin
setlength(TreeNode_list,length(TreeNode_list)+1);
TreeNode_list[fieldasinteger('level')]:=AddChildObject(TreeNode_list[last_level],fieldasstring('val'),pointer(fieldasinteger('c_key')));
end
else
begin
TreeNode_list[fieldasinteger('level')]:=AddChildObject(TreeNode_list[fieldasinteger('level')-1],fieldasstring('val'),pointer(fieldasinteger('c_key')));
end;
last_level:=fieldasinteger('level');
next;
end;

end;
treeview1.FullExpand;
end;
 
Y

yyanghhong

Unregistered / Unconfirmed
GUEST, unregistred user!
this is a joke, i think here is right place to post it.
The Evolution of a Programmer

===================
High School/Jr.High
===================
10 PRINT "HELLO WORLD"
20 END
=====================
First year in College
=====================
program Hello(input, output)
begin
writeln('Hello World');
end.

======================
Senior year in College
======================
(defun hello
(print
(cons 'Hello (list 'World))))
================
New professional
================
#include
void main(void)
{
char *message[] = {"Hello ", "World"};
int i;
for(i = 0;
i < 2;
++i)
printf("%s", message);
printf("/n");
}
====================
Seasoned professional
=====================
#include
#include
class string
{
private:
int size;
char *ptr;
public:
string() : size(0), ptr(new char('/0')) {}
string(const string &s) : size(s.size)
{
ptr = new char[size + 1];
strcpy(ptr, s.ptr);
}
~string()
{
delete [] ptr;
}
friend ostream &operator <<(ostream &, const string &);
string &operator=(const char *);
};
ostream &operator<<(ostream &stream, const string &s)
{
return(stream << s.ptr);
}
string &string::eek:perator=(const char *chrs)
{
if (this != &chrs)
{
delete [] ptr;
size = strlen(chrs);
ptr = new char[size + 1];
strcpy(ptr, chrs);
}
return(*this);
}
int main()
{
string str;
str = "Hello World";
cout << str << endl;
return(0);
}
=================
Master Programmer
=================
[
uuid(2573F8F4-CFEE-101A-9A9F-00AA00342820)
]
library LHello
{
// bring in the master library
importlib("actimp.tlb");
importlib("actexp.tlb");
// bring in my interfaces
#include "pshlo.idl"
[
uuid(2573F8F5-CFEE-101A-9A9F-00AA00342820)
]
cotype THello
{
interface IHello;
interface IPersistFile;
};
};
[
exe,
uuid(2573F890-CFEE-101A-9A9F-00AA00342820)
]
module CHelloLib
{
// some code related header files
importheader();
importheader();
importheader();
importheader("pshlo.h");
importheader("shlo.hxx");
importheader("mycls.hxx");
// needed typelibs
importlib("actimp.tlb");
importlib("actexp.tlb");
importlib("thlo.tlb");
[
uuid(2573F891-CFEE-101A-9A9F-00AA00342820),
aggregatable
]
coclass CHello
{
cotype THello;
};
};
#include "ipfix.hxx"
extern HANDLE hEvent;
class CHello : public CHelloBase
{
public:
IPFIX(CLSID_CHello);
CHello(IUnknown *pUnk);
~CHello();
HRESULT __stdcall PrintSz(LPWSTR pwszString);
private:
static int cObjRef;
};
#include
#include
#include
#include
#include "thlo.h"
#include "pshlo.h"
#include "shlo.hxx"
#include "mycls.hxx"
int CHello:cObjRef = 0;
CHello::CHello(IUnknown *pUnk) : CHelloBase(pUnk)
{
cObjRef++;
return;
}
HRESULT __stdcall CHello::printSz(LPWSTR pwszString)
{
printf("%ws/n", pwszString);
return(ResultFromScode(S_OK));
}

CHello::~CHello(void)
{
// when the object count goes to zero, stop the server
cObjRef--;
if( cObjRef == 0 )
PulseEvent(hEvent);
return;
}
#include
#include
#include "pshlo.h"
#include "shlo.hxx"
#include "mycls.hxx"
HANDLE hEvent;
int _cdecl main(
int argc,
char * argv[]
) {
ULONG ulRef;
DWORD dwRegistration;
CHelloCF *pCF = new CHelloCF();
hEvent = CreateEvent(NULL, FALSE, FALSE, NULL);
// Initialize the OLE libraries
CoInitiali, NULL);
// Initialize the OLE libraries
CoInitializeEx(NULL, COINIT_MULTITHREADED);
CoRegisterClassObject(CLSID_CHello, pCF, CLSCTX_LOCAL_SERVER,
REGCLS_MULTIPLEUSE, &dwRegistration);
// wait on an event to stop
WaitForSingleObject(hEvent, INFINITE);
// revoke and release the class object
CoRevokeClassObject(dwRegistration);
ulRef = pCF->Release();
// Tell OLE we are going away.
CoUninitialize();
return(0);
}
extern CLSID CLSID_CHello;
extern UUID LIBID_CHelloLib;
CLSID CLSID_CHello = { /* 2573F891-CFEE-101A-9A9F-00AA00342820 */
0x2573F891,
0xCFEE,
0x101A,
{ 0x9A, 0x9F, 0x00, 0xAA, 0x00, 0x34, 0x28, 0x20 }
};
UUID LIBID_CHelloLib = { /* 2573F890-CFEE-101A-9A9F-00AA00342820 */
0x2573F890,
0xCFEE,
0x101A,
{ 0x9A, 0x9F, 0x00, 0xAA, 0x00, 0x34, 0x28, 0x20 }
};
#include
#include
#include
#include
#include
#include "pshlo.h"
#include "shlo.hxx"
#include "clsid.h"
int _cdecl main(
int argc,
char * argv[]
) {
HRESULT hRslt;
IHello *pHello;
ULONG ulCnt;
IMoniker * pmk;
WCHAR wcsT[_MAX_PATH];
WCHAR wcsPath[2 * _MAX_PATH];
// get object path
wcsPath[0] = '/0';
wcsT[0] = '/0';
if( argc > 1) {
mbstowcs(wcsPath, argv[1], strlen(argv[1]) + 1);
wcsupr(wcsPath);
}
else
{
fprintf(stderr, "Object path must be specified/n");
return(1);
}
// get print string
if(argc > 2)
mbstowcs(wcsT, argv[2], strlen(argv[2]) + 1);
else
wcscpy(wcsT, L"Hello World");
printf("Linking to object %ws/n", wcsPath);
printf("Text String %ws/n", wcsT);
// Initialize the OLE libraries
hRslt = CoInitializeEx(NULL, COINIT_MULTITHREADED);
if(SUCCEEDED(hRslt)) {
hRslt = CreateFileMoniker(wcsPath, &pmk);
if(SUCCEEDED(hRslt))
hRslt = BindMoniker(pmk, 0, IID_IHello, (void **)&pHello);
if(SUCCEEDED(hRslt)) {
// print a string out
pHello->PrintSz(wcsT);
Sleep(2000);
ulCnt = pHello->Release();
}
else
printf("Failure to connect, status: %lx", hRslt);
// Tell OLE we are going away.
CoUninitialize();
}
return(0);
}
=================
Apprentice Hacker
=================
#!/usr/local/bin/perl
$msg="Hello, world./n";
if ($#ARGV >= 0) {
while(defined($arg=shift(@ARGV))) {
$outfilename = $arg;
open(FILE, ">" . $outfilename) || die "Can't write $arg: $!/n";
print (FILE $msg);
close(FILE) || die "Can't close $arg: $!/n";
}
} else
{
print ($msg);
}
1;
==================
Experienced Hacker
==================
#include
#define S "Hello, World/n"
main(){exit(printf(S) == strlen(S) ? 0 : 1);}
===============
Seasoned Hacker
===============
% cc -o a.out ~/src/misc/hw/hw.c
% a.out
===========
Guru Hacker
===========
% cat
Hello, world.
^D
=====================
AXE System programmer
=====================
LL0:
.seg "data"
.seg "text"
.proc 04
.global _main
_main:
!#PROLOGUE# 0
sethi %hi(LF26),%g1
add %g1,%lo(LF26),%g1
save %sp,%g1,%sp
!#PROLOGUE# 1
.seg "data1"
L30:
.ascii "Hello, World/012/0"
.seg "text"
.seg "data1"
L32:
.ascii "Hello, World/012/0"
.seg "text"
set L32,%o0
call _strlen,1
nop
mov %o0,%i5
set L30,%o0
call _printf,1
nop
cmp %o0,%i5
bne L2000000
nop
mov 0,%o0
b L2000001
nop
L2000000:
mov 0x1,%o0
L2000001:
call _exit,1
nop
LE26:
ret
restore
LF26 = -96
LP26 = 96
LST26 = 96
LT26 = 96
.seg "data"
0000000 0103 0107 0000 0060 0000 0020 0000 0000
0000020 0000 0030 0000 0000 0000 0054 0000 0000
0000040 033f ffff 8200 63a0 9de3 8001 1100 0000
0000060 9012 2000 4000 0000 0100 0000 ba10 0008
0000100 1100 0000 9012 2000 4000 0000 0100 00 ba10 0008
0000100 1100 0000 9012 2000 4000 0000 0100 0000
0000120 80a2 001d 1280 0005 0100 0000 9010 2000
0000140 1080 0003 0100 0000 9010 2001 4000 0000
0000160 0100 0000 81c7 e008 81e8 0000 0000 0000
0000200 4865 6c6c 6f2c 2057 6f72 6c64 0a00 4865
0000220 6c6c 6f2c 2057 6f72 6c64 0a00 0000 0000
0000240 0000 000c 0000 0608 0000 006e 0000 0010
0000260 0000 060b 0000 006e 0000 0014 0000 0286
0000300 ffff ffec 0000 0020 0000 0608 0000 0060
0000320 0000 0024 0000 060b 0000 0060 0000 0028
0000340 0000 0186 ffff ffd8 0000 004c 0000 0386
0000360 ffff ffb4 0000 0004 0500 0000 0000 0000
0000400 0000 000a 0100 0000 0000 0000 0000 0012
0000420 0100 0000 0000 0000 0000 001a 0100 0000
0000440 0000 0000 0000 0020 5f6d 6169 6e00 5f70
0000460 7269 6e74 6600 5f73 7472 6c65 6e00 5f65
0000500 7869 7400
0000504
% axe_generate -f system.uhdl
Application 'Exchange' generated
2324042350000000 source code lines
No Errors detected.
Hardware retrieval...done OK
Certification Test...done OK
Packing..............done OK
Delivery.............done OK
Application 'Exchange' delivered to customer
23456000 bytes/sec.
End processing, 2345 seconds.
===========================
Ultra high level programmer
===========================
system.uhdl :
SYSTEM
CREATE ScreenWin
SIZE 20000000/Unit=One
DESTINATION Order.dest[One]
OUTPUT CHARACTER['Hello world']
END
END
===========
New Manager
===========
10 PRINT "HELLO WORLD"
20 END
==============
Middle Manager
==============
mail -s "Hello, world." bob@b12
Bob, could you please write me a program that prints
"Hello, world."? I need it by tomorrow.
^D
==============
Senior Manager
==============
% zmail all
I need a "Hello, world." program by this afternoon.
===============
Chief Executive
===============
% message
message: Command not found
% pm
pm: Command not found
% letter
letter: Command not found.
% mail
To: ^X ^F ^C
> help mail
help: Command not found.
>what
what: Command not found
>need help
need: Command not found
> damn!
!: Event unrecognized
>exit
exit: Unknown
>quit
%
% logout

 

一个过客

Unregistered / Unconfirmed
GUEST, unregistred user!
真讨厌!连C代码都出来了!yyanghhong这个家伙真恶心!
 
Q

qiubole

Unregistered / Unconfirmed
GUEST, unregistred user!
to yyanghhong
[:D][:D][:D]
哈哈,我是说着玩的呢,我那只是表明一个多态性的问题,不过,你说indexof搜索整个区域
这一点我是不太赞同的
看看在tstrings的indexof的定义吧
function TStrings.IndexOf(const S: string): Integer;
begin
for Result := 0 to GetCount - 1 do
if CompareStrings(Get(Result), S) = 0 then
[red]Exit[/red];
Result := -1;
end;
再看看在tstringlist中的重载吧
function TStringList.IndexOf(const S: string): Integer;
begin
if not Sorted then
Result := inherited IndexOf(S) else
if not Find(S, Result) then
Result := -1;
end;
而且它有一个自动搜索父类的功能,如果是多级操作,应该是可以的,你的lastlever就不好玩咯
话又说回来了这个tstringlist是可以不用的
至于你所谓的'if there are lots of rows on the table'我有点不太明白。
如果是十万条记录,有必要作为一个分枝全部显示么;呵呵,做成两级,每级用十个分枝,
展开时再增加,不好么

该死,我的程序有个错误,竟将[red]ttreeview1.items.child写成了ttreeview1.child[/red]
我的程序试了一下,用tstringlist增对象做一万条花了[blue]16.354[/blue]秒,占内存4.656M,
不用它花了[blue]16.233[/blue]秒,占内存4.596M,cpu占用率相同,都是100%,狠吧
所以根本不用过虑[:D][:D][:D],还是让我们享受一下方便的感觉吧
小子我什么都不懂,还请赐教
 
M

MrMengyi

Unregistered / Unconfirmed
GUEST, unregistred user!
yyanghhong
真是大开眼界呀
 
Z

zjlcc

Unregistered / Unconfirmed
GUEST, unregistred user!
:)yyanghhong:你的CC公主好长呀,我详细看看先,粗看就挺有意思的!
 

侃侃

Unregistered / Unconfirmed
GUEST, unregistred user!
写了计算字数的,大概350字左右。可惜是C版。汇编版也快了.
delphi中省字的方法还没想到.
 
W

wlq

Unregistered / Unconfirmed
GUEST, unregistred user!
aimingoo:
把您的三十道題帖上來瞧瞧
 
5

5415

Unregistered / Unconfirmed
GUEST, unregistred user!
凡是投稿者,都能得到全部参赛作品以及富翁评价的完整拷贝。
不投稿就没有?呵呵,那我怎么也得投啦。
下面程序是检查系统有没有安装ADO驱动程序。

unit Unit1;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls, Registry;
type
TForm1 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;
implementation
{$R *.DFM}
function ADOInstalled: Boolean;
var
r: TRegistry;
s: string;
begin
r := TRegistry.create;
try
with r do
begin
RootKey := HKEY_CLASSES_ROOT;
OpenKey('/ADODB.Connection/CurVer', false);
s := ReadString('');
if s <> '' then
Result := True
else
Result := False;
CloseKey;
end;
finally
r.free;
end;
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
if ADOInstalled = true then
showmessage('yes')
else
showmessage('no')
end;

end
 

绝对空虚

Unregistered / Unconfirmed
GUEST, unregistred user!
[h1][/h1]5415
谢谢5451,我前一阵正为此头疼,多谢指教!
 
Y

yyanghhong

Unregistered / Unconfirmed
GUEST, unregistred user!
to qiubole,
sorry, i do
n't have other means, only for discussion.
but i still insist my point. like the code below.
function TStrings.IndexOf(const S: string): Integer;
begin
for Result := 0 to GetCount - 1 do
if CompareStrings(Get(Result), S) = 0 then
Exit;
Result := -1;
end;

you do
n't believe it would seek the entire list. you can sure that it can be
out of the loop at the begin
ing of the loop
and
ob.addobject('node1',treeview1.items.addchild(ob.objects[ob.indexof('root')] as ttreenode,'node1'));
it is not accurately, you can guarantee all of the name of nodes is unique.
my code is common, but i do
n't have any unnecessary loop.


 
O

oldppp

Unregistered / Unconfirmed
GUEST, unregistred user!
哇!高手如云!学习学习!
 

龙丹

Unregistered / Unconfirmed
GUEST, unregistred user!
唉......
悲哀!
 
A

amsea

Unregistered / Unconfirmed
GUEST, unregistred user!
高手总会在这里学到东西,而有的人总会在这里做一些没有必要的争论,
跑题始终离不开大富翁的讨论。
________________________________________

预祝本次活动圆满成功。
 
J

jilimi

Unregistered / Unconfirmed
GUEST, unregistred user!
学习学习!
 
C

cacao_cacao

Unregistered / Unconfirmed
GUEST, unregistred user!
>凡是投稿者,都能得到全部参赛作品以及富翁评价的完整拷贝。
为什么? [:(!]其实象我这样的菜鸟更有必要得到一份,我们是DELPHI的未来之星嘛[8D]
强烈要求把“见者有份”,让菜鸟们学习学习,少走弯路!!!
 
H

htw

Unregistered / Unconfirmed
GUEST, unregistred user!
怎么可能以512字节(不含空格和备注)的delphi源代码来表现一个人
在Delphi的某一方面或者某些方面的编程实力?
现在不是机器码时代了!

 

Similar threads

S
回复
0
查看
947
SUNSTONE的Delphi笔记
S
S
回复
0
查看
768
SUNSTONE的Delphi笔记
S
D
回复
0
查看
2K
DelphiTeacher的专栏
D
D
回复
0
查看
1K
DelphiTeacher的专栏
D
S
回复
0
查看
3K
SUNSTONE的Delphi笔记
S
顶部