Question

How to convert this C++ (CBuilder) Code to Delphi / Pascal

Asked by: akunyer

I'm trying to convert this few lines of codes below in C++ code for calculating the CRC and getting the data from the ModBus hardware. Could someone who are good in BCB conversion into Delphi can help me. At least 80% of the code can be convert is very helpful. I'm stuck at this point nearly 1 month . Below are some of the codes. Thanks.

unsigned short crc16table[256] =
	{
	0x0000, 0xc0c1, 0xc181, 0x0140, 0xc301, 0x03c0, 0x0280, 0xc241,
	0xc601, 0x06c0, 0x0780, 0xc741, 0x0500, 0xc5c1, 0xc481, 0x0440,
	0xcc01, 0x0cc0, 0x0d80, 0xcd41, 0x0f00, 0xcfc1, 0xce81, 0x0e40,
	0x0a00, 0xcac1, 0xcb81, 0x0b40, 0xc901, 0x09c0, 0x0880, 0xc841,
	0xd801, 0x18c0, 0x1980, 0xd941, 0x1b00, 0xdbc1, 0xda81, 0x1a40,
	0x1e00, 0xdec1, 0xdf81, 0x1f40, 0xdd01, 0x1dc0, 0x1c80, 0xdc41,
	0x1400, 0xd4c1, 0xd581, 0x1540, 0xd701, 0x17c0, 0x1680, 0xd641,
	0xd201, 0x12c0, 0x1380, 0xd341, 0x1100, 0xd1c1, 0xd081, 0x1040,
	0xf001, 0x30c0, 0x3180, 0xf141, 0x3300, 0xf3c1, 0xf281, 0x3240,
	0x3600, 0xf6c1, 0xf781, 0x3740, 0xf501, 0x35c0, 0x3480, 0xf441,
	0x3c00, 0xfcc1, 0xfd81, 0x3d40, 0xff01, 0x3fc0, 0x3e80, 0xfe41,
	0xfa01, 0x3ac0, 0x3b80, 0xfb41, 0x3900, 0xf9c1, 0xf881, 0x3840,
	0x2800, 0xe8c1, 0xe981, 0x2940, 0xeb01, 0x2bc0, 0x2a80, 0xea41,
	0xee01, 0x2ec0, 0x2f80, 0xef41, 0x2d00, 0xedc1, 0xec81, 0x2c40,
	0xe401, 0x24c0, 0x2580, 0xe541, 0x2700, 0xe7c1, 0xe681, 0x2640,
	0x2200, 0xe2c1, 0xe381, 0x2340, 0xe101, 0x21c0, 0x2080, 0xe041,
	0xa001, 0x60c0, 0x6180, 0xa141, 0x6300, 0xa3c1, 0xa281, 0x6240,
	0x6600, 0xa6c1, 0xa781, 0x6740, 0xa501, 0x65c0, 0x6480, 0xa441,
	0x6c00, 0xacc1, 0xad81, 0x6d40, 0xaf01, 0x6fc0, 0x6e80, 0xae41,
	0xaa01, 0x6ac0, 0x6b80, 0xab41, 0x6900, 0xa9c1, 0xa881, 0x6840,
	0x7800, 0xb8c1, 0xb981, 0x7940, 0xbb01, 0x7bc0, 0x7a80, 0xba41,
	0xbe01, 0x7ec0, 0x7f80, 0xbf41, 0x7d00, 0xbdc1, 0xbc81, 0x7c40,
	0xb401, 0x74c0, 0x7580, 0xb541, 0x7700, 0xb7c1, 0xb681, 0x7640,
	0x7200, 0xb2c1, 0xb381, 0x7340, 0xb101, 0x71c0, 0x7080, 0xb041,
	0x5000, 0x90c1, 0x9181, 0x5140, 0x9301, 0x53c0, 0x5280, 0x9241,
	0x9601, 0x56c0, 0x5780, 0x9741, 0x5500, 0x95c1, 0x9481, 0x5440,
	0x9c01, 0x5cc0, 0x5d80, 0x9d41, 0x5f00, 0x9fc1, 0x9e81, 0x5e40,
	0x5a00, 0x9ac1, 0x9b81, 0x5b40, 0x9901, 0x59c0, 0x5880, 0x9841,
	0x8801, 0x48c0, 0x4980, 0x8941, 0x4b00, 0x8bc1, 0x8a81, 0x4a40,
	0x4e00, 0x8ec1, 0x8f81, 0x4f40, 0x8d01, 0x4dc0, 0x4c80, 0x8c41,
	0x4400, 0x84c1, 0x8581, 0x4540, 0x8701, 0x47c0, 0x4680, 0x8641,
	0x8201, 0x42c0, 0x4380, 0x8341, 0x4100, 0x81c1, 0x8081, 0x4040
	};
 
unsigned int TForm1::calCrc(unsigned char *cp, int len)
{
	int i, index, crc=0xffff;
 
	for(i=0;i<len;i++,cp++) {
		index = ((crc ^ *cp) & 0x00ff);
		crc = ((crc >> 8) & 0x00ff) ^ crc16table[index];
	}
	return(crc);
}
 
void __fastcall TForm1::Timer3Timer(TObject *Sender)
{
    Timer3->Enabled = false;
 
    unsigned char mstr[1000];
    char str[5000], s[10];
    mstr[0] = address;
    mstr[1] = 0x03;
    mstr[2] = 0x00;
    mstr[3] = 0x00;
    mstr[4] = 0x00;
    mstr[5] = 27;
    unsigned int crc = calCrc(mstr,6);
    mstr[6] = (unsigned char)(crc & 0x00ff);
    mstr[7] = (unsigned char)(crc >> 8);
    IdUDPClient1->SendBuffer(mstr, 8);
 
    int b = IdUDPClient1->ReceiveBuffer(mstr, 1000, 3000);
    sprintf(str,"%d: ", b);
    for(int i=0;i<b;i++) {
        sprintf(s,"%2.2x ",mstr[i]);
        strcat(str,s);
    }
    Edit3->Text = str;
 
    IdUDPClient1->Active = false;
}
 
 
 
 
void __fastcall TForm1::ServerSocket1ClientRead(TObject *Sender,
      TCustomWinSocket *Socket)
{
    AnsiString buf = Socket->ReceiveText();
    Memo1->Lines->Add(buf);
 
    char command[100], add[100];
    int a;
    sscanf(buf.c_str(), "%s %s %d", command, add, &a);
 
    IdUDPClient1->Host = add;
    IdUDPClient1->Port = 10002;         // port no used
    IdUDPClient1->Active = true;
 
    replySocket = Socket;
 
    AnsiString c = StrUpper(command);
    if(c == "RETRIEVE") {
        mstr[0] = a;
        mstr[1] = 0x03;
        mstr[2] = 0x00;
        mstr[3] = 0x00;
        mstr[4] = 0x00;
        mstr[5] = 27;
        unsigned int crc = calCrc(mstr,6);
        mstr[6] = (unsigned char)(crc & 0x00ff);
        mstr[7] = (unsigned char)(crc >> 8);
 
        mstrLen = 8;
        // set to receive
        Timer2->Enabled = true;
    }
 
    if(c == "CLEAR") {
        mstr[0] = a;
        mstr[1] = 0x06;
        mstr[2] = 0x00;
        mstr[3] = 0x00;
        mstr[4] = 0x00;
        mstr[5] = 0x00;
        unsigned int crc = calCrc(mstr,6);
        mstr[6] = (unsigned char)(crc & 0x00ff);
        mstr[7] = (unsigned char)(crc >> 8);
 
        mstrLen = 8;
        // set to receive
        Timer2->Enabled = true;
    }
}
//---------------------------------------------------------------------------
 
void __fastcall TForm1::Timer2Timer(TObject *Sender)
{
    Timer2->Enabled = false;
 
    // set flag waiting for response
    waitFlag = true;
    // send command
    char str[100], reply[1000];
 
    IdUDPClient1->SendBuffer(mstr, mstrLen);
    int b = IdUDPClient1->ReceiveBuffer(mstr, 1000, 3000);
    if(b == 59) {
 
        float f;
        unsigned int val1, val2;
        // translate
        strcpy(reply,"");
        val1 = (mstr[3] << 8) + mstr[4];
        val2 = (mstr[5] << 8) + mstr[6];
        f = (val1 * 0.0078125) + (val2 * 512.0);        // KWH
        sprintf(str,"%7.3f ", f);
        strcat(reply,str);
 
        // KW
        val1 = (mstr[7] << 8) + mstr[8];
        sprintf(str,"%7.3f ", val1 * 0.004);
        strcat(reply,str);
 
        // KVAR
        val1 = (mstr[9] << 8) + mstr[10];
        sprintf(str,"%7.3f ", val1 * 0.004);
        strcat(reply,str);
 
        // VA
        val1 = (mstr[11] << 8) + mstr[12];
        sprintf(str,"%7.3f ", val1 * 0.004);
        strcat(reply,str);
 
        // power factor
        val1 = (mstr[13] << 8) + mstr[14];
        sprintf(str,"%5.3f ", val1 * 0.000030518);
        strcat(reply,str);
 
        // volt
        val1 = (mstr[15] << 8) + mstr[16];
        sprintf(str,"%7.3f ", val1 * 0.03125);
        strcat(reply,str);
 
        // volt
        val1 = (mstr[17] << 8) + mstr[18];
        sprintf(str,"%7.3f ", val1 * 0.015625);
        strcat(reply,str);
 
        // amp
        val1 = (mstr[19] << 8) + mstr[20];
        sprintf(str,"%7.3f ", val1 * 0.0039063);
        strcat(reply,str);
 
        // kw
        val1 = (mstr[21] << 8) + mstr[22];
        sprintf(str,"%7.3f ", val1 * 0.001);
        strcat(reply,str);
 
        // kw
        val1 = (mstr[23] << 8) + mstr[24];
        sprintf(str,"%7.3f ", val1 * 0.001);
        strcat(reply,str);
 
        // kw
        val1 = (mstr[25] << 8) + mstr[26];
        sprintf(str,"%7.3f ", val1 * 0.001);
        strcat(reply,str);
 
        // power factor
        val1 = (mstr[27] << 8) + mstr[28];
        sprintf(str,"%5.3f ", val1 * 0.000030518);
        strcat(reply,str);
 
        // power factor
        val1 = (mstr[29] << 8) + mstr[30];
        sprintf(str,"%5.3f ", val1 * 0.000030518);
        strcat(reply,str);
 
        // power factor
        val1 = (mstr[31] << 8) + mstr[32];
        sprintf(str,"%5.3f ", val1 * 0.000030518);
        strcat(reply,str);
 
        // volt
        val1 = (mstr[33] << 8) + mstr[34];
        sprintf(str,"%7.3f ", val1 * 0.03125);
        strcat(reply,str);
 
        // volt
        val1 = (mstr[35] << 8) + mstr[36];
        sprintf(str,"%7.3f ", val1 * 0.03125);
        strcat(reply,str);
 
        // volt
        val1 = (mstr[37] << 8) + mstr[38];
        sprintf(str,"%7.3f ", val1 * 0.03125);
        strcat(reply,str);
 
        // volt
        val1 = (mstr[39] << 8) + mstr[40];
        sprintf(str,"%7.3f ", val1 * 0.015625);
        strcat(reply,str);
 
        // volt
        val1 = (mstr[41] << 8) + mstr[42];
        sprintf(str,"%7.3f ", val1 * 0.015625);
        strcat(reply,str);
 
        // volt
        val1 = (mstr[43] << 8) + mstr[44];
        sprintf(str,"%7.3f ", val1 * 0.015625);
        strcat(reply,str);
 
        // amps
        val1 = (mstr[45] << 8) + mstr[46];
        sprintf(str,"%7.3f ", val1 * 0.0039063);
        strcat(reply,str);
 
        // amps
        val1 = (mstr[47] << 8) + mstr[48];
        sprintf(str,"%7.3f ", val1 * 0.0039063);
        strcat(reply,str);
 
        // amps
        val1 = (mstr[49] << 8) + mstr[50];
        sprintf(str,"%7.3f ", val1 * 0.0039063);
        strcat(reply,str);
 
        // kw
        val1 = (mstr[51] << 8) + mstr[52];
        sprintf(str,"%7.3f ", val1 * 0.004);
        strcat(reply,str);
 
        // kw
        val1 = (mstr[53] << 8) + mstr[54];
        sprintf(str,"%7.3f ", val1 * 0.004);
        strcat(reply,str);
 
        // amps
        val1 = (mstr[55] << 8) + mstr[56];
        sprintf(str,"%7.3f ", val1 * 0.004);
        strcat(reply,str);
 
        // send to replySocket
        replySocket->SendBuf(reply, strlen(reply));
 
        // log
        Memo1->Lines->Add(reply);
    }
    else {
        // error
        sprintf(str,"%d chars received - ",b);
        if(!b)
            strcpy(reply,"0");  // no reply
        else {
            if(mstr[1] == 0x06) {
                // clear kWH, send MSB address 0001
                mstr[3] = 0x01;
                unsigned int crc = calCrc(mstr,6);
                mstr[6] = (unsigned char)(crc & 0x00ff);
                mstr[7] = (unsigned char)(crc >> 8);
                IdUDPClient1->SendBuffer(mstr, mstrLen);
                b = IdUDPClient1->ReceiveBuffer(mstr, 1000, 3000);
            }
            strcpy(reply,"OK"); // presumably ok
        }
        replySocket->SendBuf(reply, strlen(reply));
        strcat(str,reply);
        Memo1->Lines->Add(str);
    }
    IdUDPClient1->Active = false;   // close connection
}
//---------------------------------------------------------------------------

                                  
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:
86:
87:
88:
89:
90:
91:
92:
93:
94:
95:
96:
97:
98:
99:
100:
101:
102:
103:
104:
105:
106:
107:
108:
109:
110:
111:
112:
113:
114:
115:
116:
117:
118:
119:
120:
121:
122:
123:
124:
125:
126:
127:
128:
129:
130:
131:
132:
133:
134:
135:
136:
137:
138:
139:
140:
141:
142:
143:
144:
145:
146:
147:
148:
149:
150:
151:
152:
153:
154:
155:
156:
157:
158:
159:
160:
161:
162:
163:
164:
165:
166:
167:
168:
169:
170:
171:
172:
173:
174:
175:
176:
177:
178:
179:
180:
181:
182:
183:
184:
185:
186:
187:
188:
189:
190:
191:
192:
193:
194:
195:
196:
197:
198:
199:
200:
201:
202:
203:
204:
205:
206:
207:
208:
209:
210:
211:
212:
213:
214:
215:
216:
217:
218:
219:
220:
221:
222:
223:
224:
225:
226:
227:
228:
229:
230:
231:
232:
233:
234:
235:
236:
237:
238:
239:
240:
241:
242:
243:
244:
245:
246:
247:
248:
249:
250:
251:
252:
253:
254:
255:
256:
257:
258:
259:
260:
261:
262:
263:
264:
265:
266:
267:
268:
269:
270:
271:
272:
273:
274:
275:
276:
277:
278:
279:
280:
281:
282:
283:
284:
285:
286:
287:
288:
289:
290:
291:
292:
293:
294:
295:
296:
297:
298:
299:
300:
301:
302:
303:
304:
305:
306:
307:

Select allOpen in new window

This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.

Subscribe now for full access to Experts Exchange and get

Instant Access to this Solution

  • Plus...
  • 30 Day FREE access, no risk, no obligation
  • Collaborate with the world's top tech experts
  • Unlimited access to our exclusive solution database
  • Never be left without tech help again

Subscribe Now

Asked On
2009-08-24 at 18:04:39ID24678491
Tags

Delphi

,

Cbuilder

,

CBB

Topics

C++ Builder

,

Delphi IDE

,

C Programming Language

Participating Experts
1
Points
20
Comments
2

Trusted by hundreds of thousands everyday for fast, accurate and reliable tech support.

  • "The time we save is the biggest benefit of Experts Exchange to Warner Bros. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange." Mike Kapnisakis, Warner Bros.
  • "Our team likes having a resource that is more secure than just using Google and most experts using this service really know their stuff. It's nice to look here first versus using Google." Dayna Sellner, Lockheed Martin
  • "Anytime that I've been stumped with a problem, 9 out of 10 times Experts Exchange has either the accepted solution or an open discussion of the potential solution to the problem." Kenny Red, eBay Inc.

See what Experts Exchange can do for you.

Got a question?

We've got the answer.

Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.

Screenshot of Experts Exchange Knowledgebase

Need individual assistance?

Our experts are ready to help.

If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.

Screenshot of Experts Exchange Knowledgebase

Want to learn from the best?

Read articles from industry experts.

Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.

Screenshot of an Article

Working on a long term project?

Store your work and research.

Save solutions to your questions, answers you’ve discovered through searching plus helpful articles in your personal knowledgebase for easy future access.

Screenshot of Experts Exchange Knowledgebase

Access the answers to your technology questions today.

Subscribe Now

30-day free trial. Register in 60 seconds.

What Makes Experts Exchange Unique?

Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Trusted by the world's most respected brands.

image of each brand's logo

Faithfully serving IT professionals since 1996.

Experts Exchange Logo

Try it out and discover for yourself.

Subscribe Now

30-day free trial. Register in 60 seconds.

Related Solutions

  1. Delphi and Turbo Pascal
    What are the major differences between Delphi and Turbo Pascal?
  2. CRCs - Calculating them quickly for a File
    I have written some code to Calculate the CRCs of a bunch of files. The trouble is that I have done all the CRC calculations using binary digits held in strings so it is VERY S.L.O.W. !! I did it this way, because it makes the code so easy to understand - but the draw back...
  3. Converting Pascal to Delphi
    Can I convert sources codes wroten in Turbo Pascal 6.0 to Delphi 2.0, and how?
  4. Pascal Units In Delphi!?
    Is it possible to use the procedures and functions of a pascal unit in Delphi? I know that it's not directly possible, but may be you have some idea about some indirect way, for example creating a dll file with Pascal and then call the dll from Delphi! Is this possible? If y...
  5. How to merge BCB module into Delphi?
    Hi All: BCB and Delphi use the same VCL and many similar packages. It is easy to merge Delphi forms and codes into BCB. But it is few topics about BCB application merge into Delphi. Anyone can tell me how to merge BCB modules into Delphi with any style such as packages,DLL an...

Free Tech Articles

  1. WARNING: 5 Reasons why you should NEVER fix a computer for free.
    It is in our nature to love the puzzle. We are obsessed. The lot of us. We love puzzles. We love the challenge. We thrive on finding the answer. We hate disarray. It bothers us deep in our soul. W...
  2. SCCM OSD Basic troubleshooting
    SCCM 2007 OSD is a fantastic way to deploy operating systems, however, like most things SCCM issues can sometimes be difficult to resolve due to the sheer volume of logs to sift through and the dispe...
  3. Migrate Small Business Server 2003 to Exchange 2010 and Windows 2008 R2
    This guide is intended to provide step by step instructions on how to migrate from Small Business Server 2003 to Windows 2008 R2 with Exchange 2010. For this migration to work you will need the fo...
  4. Create a Win7 Gadget
    This article shows you how to create a simple "Gadget" -- a sort of mini-application supported by Windows 7 and Vista. Gadgets can be dropped anywhere on the desktop to provide instant information, ...
  5. Outlook continually prompting for username and password
    There have been a lot of questions recently regarding Outlook prompting for a username and password whilst using Exchange 2007. There are a few reasons why this would happen and I will try to cover t...
  6. Backup Exchange 2010 Information Store using Windows Backup
    There seems to be quite a lot of confusion around the ability to backup Exchange 2010 using the built in Windows Backup feature. This stems from the omission of this feature prior to Exchange 2007 s...

Cloud Class Webinars

  1. Avoiding Bugs in Microsoft Access
    Alison Balter takes and in-depth look at avoiding bugs in Access. In this webinar you will learn about using the immediate window to debug your applications, invoking the debugger, using breakpoints to troubleshoot, stepping through code, setting the next statement to execute, ...
  2. Top 10 Best New Features in Visio 2010
    Scott Helmers gives live demonstrations of the top 10 new features in Visio 2010. This webinar will teach you how to create compelling diagrams by adding shapes to the page with a single click, linking the shapes in a diagram to data in Excel (or SQL Server, or SharePoint), ...
  3. IT Consultant Business Secrets Revealed
    Michael Munger, Experts Exchange tech pro and IT consultant, pulls back the curtain on his very successful businesses and answers question on every IT consultant and business owner should know about. He shares secrets on what he did to solve the 5 most common problems in IT, ...
  4. Disaster Recovery and Business Continuity
    Quest CTO, Mike Billon, gives an overview of the steps involved in building a dunamic disaster recovery plan. Through case studies and an examination of software/hardware tooles for monitoring and testing, you'll gain a better understandin of where you are, where you want ...
  5. Organize Your Visio Diagrams with Containers and Lists
    Scott Helmers uses cross functional flowcharts, wireframe diagrams, data graphic legends and seating charts to teach you: how to ustilize all three new structured diagram components in Visio 2010, the best practices for organizeing shapes in previous version of Visio, how to organize ...
  6. How to Us Objects, Properties, Events and Methods in Microsoft Access
    Alison Dalter gives an in-depbth look at objects, properties, events and methods in Microsoft Access. In this webinar you will learn about using the object browser, referring to objects, working with properties and methods, working with object variables, understanding the ...

Join the Community

Give a Little. Get a Lot.

Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.

Join the Community

Answers

 

by: Geert_GruwezPosted on 2009-08-25 at 07:13:17ID: 25177789

here is the CRC check unit

(*************************************************
 
   CRC32 Library for Delphi(tm)
   Copyright © 2002 NAG Software Solutions
   All rights reserved
 
   http://www.nagsoftware.com/
 
   Please refer to the included README.TXT
   for details.
 
*************************************************)
 
unit CRC32;
 
interface
 
uses
  Classes, SysUtils;
 
const
  ValueTable: array [0..255] of Longword =
   ($00000000, $77073096, $ee0e612c, $990951ba,
    $076dc419, $706af48f, $e963a535, $9e6495a3,
    $0edb8832, $79dcb8a4, $e0d5e91e, $97d2d988,
    $09b64c2b, $7eb17cbd, $e7b82d07, $90bf1d91,
    $1db71064, $6ab020f2, $f3b97148, $84be41de,
    $1adad47d, $6ddde4eb, $f4d4b551, $83d385c7,
    $136c9856, $646ba8c0, $fd62f97a, $8a65c9ec,
    $14015c4f, $63066cd9, $fa0f3d63, $8d080df5,
    $3b6e20c8, $4c69105e, $d56041e4, $a2677172,
    $3c03e4d1, $4b04d447, $d20d85fd, $a50ab56b,
    $35b5a8fa, $42b2986c, $dbbbc9d6, $acbcf940,
    $32d86ce3, $45df5c75, $dcd60dcf, $abd13d59,
    $26d930ac, $51de003a, $c8d75180, $bfd06116,
    $21b4f4b5, $56b3c423, $cfba9599, $b8bda50f,
    $2802b89e, $5f058808, $c60cd9b2, $b10be924,
    $2f6f7c87, $58684c11, $c1611dab, $b6662d3d,
    $76dc4190, $01db7106, $98d220bc, $efd5102a,
    $71b18589, $06b6b51f, $9fbfe4a5, $e8b8d433,
    $7807c9a2, $0f00f934, $9609a88e, $e10e9818,
    $7f6a0dbb, $086d3d2d, $91646c97, $e6635c01,
    $6b6b51f4, $1c6c6162, $856530d8, $f262004e,
    $6c0695ed, $1b01a57b, $8208f4c1, $f50fc457,
    $65b0d9c6, $12b7e950, $8bbeb8ea, $fcb9887c,
    $62dd1ddf, $15da2d49, $8cd37cf3, $fbd44c65,
    $4db26158, $3ab551ce, $a3bc0074, $d4bb30e2,
    $4adfa541, $3dd895d7, $a4d1c46d, $d3d6f4fb,
    $4369e96a, $346ed9fc, $ad678846, $da60b8d0,
    $44042d73, $33031de5, $aa0a4c5f, $dd0d7cc9,
    $5005713c, $270241aa, $be0b1010, $c90c2086,
    $5768b525, $206f85b3, $b966d409, $ce61e49f,
    $5edef90e, $29d9c998, $b0d09822, $c7d7a8b4,
    $59b33d17, $2eb40d81, $b7bd5c3b, $c0ba6cad,
    $edb88320, $9abfb3b6, $03b6e20c, $74b1d29a,
    $ead54739, $9dd277af, $04db2615, $73dc1683,
    $e3630b12, $94643b84, $0d6d6a3e, $7a6a5aa8,
    $e40ecf0b, $9309ff9d, $0a00ae27, $7d079eb1,
    $f00f9344, $8708a3d2, $1e01f268, $6906c2fe,
    $f762575d, $806567cb, $196c3671, $6e6b06e7,
    $fed41b76, $89d32be0, $10da7a5a, $67dd4acc,
    $f9b9df6f, $8ebeeff9, $17b7be43, $60b08ed5,
    $d6d6a3e8, $a1d1937e, $38d8c2c4, $4fdff252,
    $d1bb67f1, $a6bc5767, $3fb506dd, $48b2364b,
    $d80d2bda, $af0a1b4c, $36034af6, $41047a60,
    $df60efc3, $a867df55, $316e8eef, $4669be79,
    $cb61b38c, $bc66831a, $256fd2a0, $5268e236,
    $cc0c7795, $bb0b4703, $220216b9, $5505262f,
    $c5ba3bbe, $b2bd0b28, $2bb45a92, $5cb36a04,
    $c2d7ffa7, $b5d0cf31, $2cd99e8b, $5bdeae1d,
    $9b64c2b0, $ec63f226, $756aa39c, $026d930a,
    $9c0906a9, $eb0e363f, $72076785, $05005713,
    $95bf4a82, $e2b87a14, $7bb12bae, $0cb61b38,
    $92d28e9b, $e5d5be0d, $7cdcefb7, $0bdbdf21,
    $86d3d2d4, $f1d4e242, $68ddb3f8, $1fda836e,
    $81be16cd, $f6b9265b, $6fb077e1, $18b74777,
    $88085ae6, $ff0f6a70, $66063bca, $11010b5c,
    $8f659eff, $f862ae69, $616bffd3, $166ccf45,
    $a00ae278, $d70dd2ee, $4e048354, $3903b3c2,
    $a7672661, $d06016f7, $4969474d, $3e6e77db,
    $aed16a4a, $d9d65adc, $40df0b66, $37d83bf0,
    $a9bcae53, $debb9ec5, $47b2cf7f, $30b5ffe9,
    $bdbdf21c, $cabac28a, $53b39330, $24b4a3a6,
    $bad03605, $cdd70693, $54de5729, $23d967bf,
    $b3667a2e, $c4614ab8, $5d681b02, $2a6f2b94,
    $b40bbe37, $c30c8ea1, $5a05df1b, $2d02ef8d);
 
function CalculateCRC(FileName: string): Longword;
function CalculateCRCFromStream(var Stream: TFileStream): Longword;
 
implementation
 
function CalculateCRCFromStream(var Stream: TFileStream): Longword;
var
  Buffer: array[1..8192] of Byte;
  I, ReadCount: Integer;
  TempResult: Longword;
begin
  {Calculate the CRC32 image for Stream}
  TempResult := $FFFFFFFF;
  while (Stream.Position <> Stream.Size) do begin
    ReadCount := Stream.Read(Buffer, SizeOf(Buffer));
    for I := 1 to ReadCount do
      TempResult := ((TempResult shr 8) and $FFFFFF) xor ValueTable[(TempResult xor Longword(Buffer[I])) and $FF];
  end;
  Result := not TempResult;
end;
 
function CalculateCRC(FileName: string): Longword;
var
  Stream: TFileStream;
begin
  {Create a stream to hold the file specified by FileName}
  Stream := TFileStream.Create(FileName, fmOpenRead or fmShareDenyWrite);
  {Attempt to calculate the CRC32 for the stream}
  try
    Result := CalculateCRCFromStream(Stream);
  finally
    Stream.Free;
  end;
end;
 
end.

                                              
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:
86:
87:
88:
89:
90:
91:
92:
93:
94:
95:
96:
97:
98:
99:
100:
101:
102:
103:
104:
105:
106:
107:
108:
109:
110:
111:
112:
113:
114:
115:
116:
117:
118:
119:
120:
121:
122:
123:

Select allOpen in new window

 

by: akunyerPosted on 2009-08-31 at 18:42:17ID: 25227975

Looks like its is hard for people to help me. Anyway , i already convert it myself . lol

20120131-EE-VQP-002

3 Ways to Join

30-Day Free Trial

The Experts

98% positive feedback on 31,087 answers since March 2000. angeliii is a Microsoft Most Valuable Professional for his work with MS SQL Server & Develoment.

He has also proven his knowledge of Visual Basic Programming, PHP Scripting and Oracle Databases.

The Experts

97% positive feedback on 10,752 answers since July 2000. lrmoore has more than 18 years experience in the networking industry.

The six-time Mircosoft MVPs specialties include firewalls, virtual private networking, and network management.

Testimonials

"...and excellent source for support... Kind of like having your very own IT dept." Electriciansnet

Testimonials

"I was apprehensive at signing up at first. However... it has already made my life as an IT administrator much easier." JaCrews

Testimonials

"WOW! You guys have great, active, and knowledgeable people on here." moore50

Business Clients

Business Clients

In the Press

"If you’ve got a question... Experts Exchange can supply an answer.”

In the Press

"...an invaluable aid for both IT professionals and those who require tech support."

In the Press

"where IT professionals provide quick answers on just about any topic"

Business Account Plans

Loading Advertisement...