Delphi7's ancient Chinese Translation System

Source: Internet
Author: User
Tags comparison table

A few days ago, I helped my friend get an ancient Chinese text and Word Translation System. First, I declare that I was going to get the ancient Chinese Text Translation System (which can translate sentences). But after careful consideration, I feel that I can only make a word translation system. after all, I think I have never learned the Delphi language. I remember that we were supposed to teach this language last semester, but I didn't pay it in the end. I also bought the teaching materials early, but there was nothing. The teacher called me to see it, finally, it took me a week to get a system that I felt bad about when I met a friend.

Think about it. You can actually get the ancient text translation system. But you can't learn it yourself. It seems that you have to work harder in the future. Now, Let's sum up your learning experience, for future generations (the ancient text translation system has never appeared on the Internet, and I hope to be able to get it out in the future) after all, I have learned C # and I want to learn C ++. As for Java, because the school mainly teaches Java, the basic knowledge is also acceptable. I used VB to get a score management system. I always felt that VB is similar to Delphi, and it is very simple. Of course, the functions are not as good as C ++, Java, and C. I don't know what language I'm going to use. It's the main skill C # now. Let's go out to work and talk about it. If you really need it, java or C ++ is not necessarily used.

Let's introduce the ancient Chinese dictionary now!

Development Environment: XP SP2 + Delphi7.0 + access2003

First, use access2003 to create a database: wzdb

Create a table (wenzi ):

Serial number (automatic serial number)

GW text 50

BHW text 200

The main interface is designed as follows:

The main interface contains three ttoolbuttons, A timagelist control. For specific names, you can see the code. After all, this system is not difficult.

The main interface code is as follows:

Unit u_main;

Interface

Uses
Windows, messages, sysutils, variants, classes, graphics, controls, forms,
Dialogs, registry, imglist, comctrls, toolwin;

Type
Tf_main = Class (tform)
Coolbar1: tcoolbar;
Toolbar1: ttoolbar;
Toolbtn_dzb: ttoolbutton;
Toolbtn_fy: ttoolbutton;
Toolbtn_close: ttoolbutton;
Toolbutton4: ttoolbutton;
Imagelist1: timagelist;
Toolbutton1: ttoolbutton;
Procedure toolbtn_closeclick (Sender: tobject );
Procedure toolbtn_dzbclick (Sender: tobject );
Procedure toolbtn_fyclick (Sender: tobject );
Private
{Private Declarations}
Public
{Public declarations}
End;

VaR
F_main: tf_main;

Implementation

Uses u_dzb, u_fy;

{$ R *. DFM}

Procedure tf_main.toolbtn_closeclick (Sender: tobject );
Begin
Close;
End;

Procedure tf_main.toolbtn_dzbclick (Sender: tobject );
Begin
// Comparison table
Application. createform (tf_dzb, f_dzb );
F_dzb.showmodal;
F_dzb.free;
End;

Procedure tf_main.toolbtn_fyclick (Sender: tobject );
Begin
// Translation
Application. createform (tf_fy, f_fy );
F_fy.showmodal;
F_fy.free;
End;
End.

The application code of the system is as follows:

Program pwww;

Uses
Forms,
U_main in 'U _ main. pa' {f_main };

{$ R *. Res}

Begin
Application. initialize;
Application. Title: = 'translation system ';
Application. createform (tf_main, f_main );
Application. Run;
End.

The table comparison Interface Design for adding a dictionary data file is not described here, including two tlabel, two tedit, four tbutton, one tTable, one tdatabase, and one tdatasource control. The Code is as follows:

 

Unit u_dzb;

Interface

Uses
Windows, messages, sysutils, variants, classes, graphics, controls, forms,
Dialogs, grids, dbgrids, registry, stdctrls, buttons, DB, dbtables;

Type
Tf_dzb = Class (tform)
Groupbox1: tgroupbox;
Label1: tlabel;
Edit1: tedit;
Edit2: tedit;
Label2: tlabel;
Btn_add: tbitbtn;
Btn_del: tbitbtn;
Btn_save: tbitbtn;
Btn_close: tbitbtn;
Dbgrid1: TDBGrid;
Performance1: tdatasource;
Editbtn: tbutton;
Table1: tTable;
Database1: tdatabase;
Procedure formshow (Sender: tobject );
Procedure btn_closeclick (Sender: tobject );
Procedure btn_addclick (Sender: tobject );
Procedure editbtnclick (Sender: tobject );
Procedure btn_delclick (Sender: tobject );
Procedure btn_saveclick (Sender: tobject );
Procedure formcreate (Sender: tobject );
Procedure formdestroy (Sender: tobject );
Private
{Private Declarations}
Public
{Public declarations}
End;

VaR
F_dzb: tf_dzb;
PS: string;

Implementation

{$ R *. DFM}

Procedure tf_dzb.formshow (Sender: tobject); // initialization table
Begin
F_dzb.top := 100;
F_dzb.left: = 100;
PS: = table1.bookmark; // initial position of the pointer
End;

Procedure tf_dzb.btn_closeclick (Sender: tobject); // close
Begin
Close;
End;

Procedure tf_dzb.btn_addclick (Sender: tobject); // Add
Begin
With Table1 do
Begin
Open;
Table1.indexfieldnames: = '文 ';
If table1.findkey ([edit1.text]) then
Begin
Showmessage ('this word exists in the dictionary. Please add it again! ');
End
Else
Begin
Edit;
Append;
Table1.fieldbyname ('ancient 文'). asstring: = trim (edit1.text );
Table1.fieldbyname ('vernacular '). asstring: = trim (edit2.text );
Post;
End;
Table1.bookmark: = Ps; // the pointer returns the initial position.
Edit1.text: = '';
Edit2.text: = '';
End;
End;
Procedure tf_dzb.editbtnclick (Sender: tobject); // modify
VaR
STR: string;
Begin
STR: = inputbox ('modify', 'Modified to: ', dbgrid1.selectedfield. asstring );
Table1.edit;
Dbgrid1.selectedfield. asstring: = STR;
End;
Procedure tf_dzb.btn_delclick (Sender: tobject); // Delete
Begin
If application. MessageBox ('Are you sure you want to delete this record? ',' Hint ', mb_yesno) = id_yes then
Begin
Try
Table1.delete;
Application. MessageBox ('deleted successfully. ', 'hs', 64 );
Except
Application. MessageBox ('System error, deletion failed. ', 'hs', 64)
End;
End;
End;
Procedure tf_dzb.btn_saveclick (Sender: tobject); // save
Begin
Table1.refresh;
Application. MessageBox ('saved successfully', 'hs', 64 );
End;
Procedure createsource; // automatically register the data source
VaR
Registertemp: Tregistry;
Bdata: array [0 .. 0] of byte;
Begin
Registertemp: = Tregistry. Create;
With registertemp do
Begin
Rootkey: = HKEY_LOCAL_MACHINE;
If openkey ('Software/ODBC. INI/ODBC Data Sources ', true) then
Begin
Writestring ('wenyanwen', 'Microsoft access Driver (*. mdb )');
End
Else
Begin
Showmessage ('failed to add ODBC Data source ');
Exit;
End;
Closekey;
If openkey ('Software/ODBC. INI/wenyanwen', true) then
Begin
Writestring ('dbq', 'c:/fyxt/wzdb. mdb ');
Writestring ('description', 'My new source ');
Writestring ('driver ', 'c:/Windows/system32/odbcjt32.dll ');
Writeinteger ('driverid', 25 );
Writestring ('fil ', 'Ms access ');
Writeinteger ('Safety ransactions', 0 );
Writestring ('uid', ''); // User Name
Bdata [0]: = 0;
Writebinarydata ('clusive ', bdata, 1 );
Writebinarydata ('readonly', bdata, 1 );
End
Else
Begin
Showmessage ('failed to add ODBC Data source ');
Exit;
End;
Closekey;
If openkey ('Software/ODBC. INI/wenyanwen/engines/jet', true) then
Begin
Writestring ('implicitcommitsync ','');
Writeinteger ('max buffersize', 2048 );
Writeinteger ('pagetimeout', 5 );
Writeinteger ('threads', 3 );
Writestring ('usercommitsync', 'yes ');
End
Else
Begin
Showmessage ('failed to add ODBC Data source ');
Exit;
End;
Closekey;
Free;
End;
End;
Procedure autologo; // automatically log on to the custom database
VaR
Mydsn: string;
Begin
Mydsn: = 'wenyanwen ';
With f_dzb.database1 do
Begin
Params. Values ['username']: = '';
Params. Values ['Password']: = '';
Loginprompt: = false;
Aliasname: = 'mydsn ';
End;
With f_dzb.table1 do
Begin
Databasename: = 'wenyanwen ';
Tablename: = 'wenzi ';
Open;
Active: = true;
End;
End;
Procedure tf_dzb.formcreate (Sender: tobject );
Begin
Createsource;
Autologo;
End;
Procedure tf_dzb.formdestroy (Sender: tobject );
Begin
Table1.close;
End;

End.

The automatically registered data source is added. (However, this automatically registered data source is valid only when you develop the system on drive C. Otherwise, it is invalid. However, if you create an installation package, follow the theory below, this problem is solved), and the data source is automatically registered, you need to add Registry on uses.

The translation design interface consists of three ttoolbuttons, one tedit, one tmemon, and one tTable control. The design interface is not described here. The Code is as follows:

Unit u_fy;

Interface

Uses
Windows, messages, sysutils, variants, classes, graphics, controls, forms,
Dialogs, extctrls, stdctrls, comctrls, toolwin, DB, dbtables;

Type
Tf_fy = Class (tform)
Coolbar1: tcoolbar;
Toolbar1: ttoolbar;
Fybtn: ttoolbutton;
Toolbutton4: ttoolbutton;
Toolbutton5: ttoolbutton;
Table1: tTable;
Edit1: tedit;
Memo1: tmemo;
Toolbutton1: ttoolbutton;
Toolbutton2: ttoolbutton;
Procedure fybtnclick (Sender: tobject );
Procedure formcreate (Sender: tobject );
Procedure toolbutton5click (Sender: tobject );
Procedure toolbutton1click (Sender: tobject );
Private
{Private Declarations}
Public
{Public declarations}
End;

VaR
F_fy: tf_fy;

Implementation

Uses u_main;

{$ R *. DFM}

Procedure tf_fy.fybtnclick (Sender: tobject); // Translation
Begin
Table1.indexfieldnames: = '文 ';
If table1.findkey ([edit1.text]) then
Begin
Memo1.text: = table1.fieldbyname ('vernacular '). asstring
End
Else
Memo1.text: = edit1.text;
End;
Procedure tf_fy.formcreate (Sender: tobject); // initialize the translation window
Begin
Edit1.height: = 209;
Edit1.width: = 249;
End;
Procedure tf_fy.toolbutton5click (Sender: tobject); // close
Begin
Close;
End;

Procedure tf_fy.toolbutton1click (Sender: tobject); // clear
Begin
Edit1.text: = '';
Memo1.text: = '';
End;

End.

 

I wanted to upload a piece of data. I don't know why. I can't upload it. The uploaded images last year are so dizzy that I don't know what went wrong.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.